Charts - how to listen to series selection

Hi all,

Is there a way to know when the user selects/clicks on a Series of a Pie Chart for instance?

The below doesn’t seem to help.


        chart.addChartSelectionListener(new ChartSelectionListener() {
            public void onSelection(ChartSelectionEvent e) {
                System.out.println(e.getComponent() + " " + e.getValueStart() + " " + e.getValueEnd() + " " + e.getSelectionEnd());
            }
        });
        chart.addLegendItemClickListener(new LegendItemClickListener() {
            public void onClick(LegendItemClickEvent e) {
                System.out.println(e.getSource() + " " + e.getSeries());
            }
        });
        chart.addChartClickListener(new ChartClickListener() {
            public void onClick(ChartClickEvent e) {
                System.out.println(e.getxAxisValue() + " " + e.getyAxisValue());
            }
        });

Hi,

Use point click listener. Slices are data points in pie chart.

cheers,
matti

Hi All.

I’m getting these error

[s]

HTTP Status 500 -


type Exception report

message
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory
com.vaadin.server.VaadinServlet.handleServiceException(VaadinServlet.java:580)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:343)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

root cause

java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory
com.vaadin.addon.charts.Chart.(Chart.java:137)
com.vaadin.addon.charts.Chart.(Chart.java:154)
com.example.grafico.GraficoUI.init(GraficoUI.java:20)
com.vaadin.ui.UI.doInit(UI.java:529)
com.vaadin.server.AbstractCommunicationManager.getBrowserDetailsUI(AbstractCommunicationManager.java:2468)
com.vaadin.server.AbstractCommunicationManager.handleBrowserDetailsRequest(AbstractCommunicationManager.java:2362)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:325)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

root cause

java.lang.ClassNotFoundException: com.google.gson.TypeAdapterFactory from BaseClassLoader@1a5da52{vfs:///D:/Projetos/GWT/.metadata/.plugins/org.jboss.ide.eclipse.as.core/jboss-6.1.0.Final_Runtime_Server1369766801891/deploy/grafico.war}
org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480)
java.lang.ClassLoader.loadClass(Unknown Source)
com.vaadin.addon.charts.Chart.(Chart.java:137)
com.vaadin.addon.charts.Chart.(Chart.java:154)
com.example.grafico.GraficoUI.init(GraficoUI.java:20)
com.vaadin.ui.UI.doInit(UI.java:529)
com.vaadin.server.AbstractCommunicationManager.getBrowserDetailsUI(AbstractCommunicationManager.java:2468)
com.vaadin.server.AbstractCommunicationManager.handleBrowserDetailsRequest(AbstractCommunicationManager.java:2362)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:325)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

note The full stack trace of the root cause is available in the JBoss Web/3.0.0-CR2 logs.


JBoss Web/3.0.0-CR2

[/s]

With that code

[s]

package com.example.grafico;

import com.vaadin.addon.charts.Chart;
import com.vaadin.addon.charts.model.ChartType;
import com.vaadin.addon.charts.model.Configuration;
import com.vaadin.addon.charts.model.ListSeries;
import com.vaadin.addon.charts.model.Marker;
import com.vaadin.addon.charts.model.PlotOptionsLine;
import com.vaadin.addon.charts.model.XAxis;
import com.vaadin.addon.charts.model.YAxis;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings(“serial”)
public class GraficoUI extends UI {

@Override
protected void init(VaadinRequest request) {
	final VerticalLayout layout = new VerticalLayout();
	layout.setMargin(true);
	setContent(layout);
	layout.addComponent(new Label("Thank you for clicking"));
	
	Chart chart = new Chart(ChartType.COLUMN);
	chart.setWidth("300px");
	chart.setHeight("300px");
	
	Configuration conf = new Configuration();
	conf.setTitle("Reinder");
	conf.setSubTitle("no one");
	
	PlotOptionsLine plotOptions = new PlotOptionsLine();
	plotOptions.setMarker(new Marker(false));
	conf.setPlotOptions(plotOptions);
	
	ListSeries series = new ListSeries("Diameter");
	series.setData(4900, 12100, 12800, 6800, 14300, 125000, 51100, 49500);
	conf.addSeries(series);
	
	XAxis xAxis = new XAxis();
	xAxis.setCategories("Mercury", "Venus", "Earth",
			             "Mars", "Jupiter", "Saturn", "Uranus", "Neptune");
	xAxis.setTitle("P)lanet");
	conf.addxAxis(xAxis);
	
	YAxis yAxis = new YAxis();
	yAxis.setTitle("Diameter");
	yAxis.getLabels().setFormatter("function() {return Math.floor(this.value/1000) + \'Mm\';}");
	yAxis.getLabels().setStep(2);
	conf.addyAxis(yAxis);
	
}

}

[/s]

Please Help me.

Oh so sorry, I did wanted to write it

[u]

HTTP Status 500 -


type Exception report

message
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory
com.vaadin.server.VaadinServlet.handleServiceException(VaadinServlet.java:580)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:343)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

root cause

java.lang.NoClassDefFoundError: com/google/gson/TypeAdapterFactory
com.vaadin.addon.charts.Chart.(Chart.java:137)
com.vaadin.addon.charts.Chart.(Chart.java:154)
com.example.grafico.GraficoUI.init(GraficoUI.java:20)
com.vaadin.ui.UI.doInit(UI.java:529)
com.vaadin.server.AbstractCommunicationManager.getBrowserDetailsUI(AbstractCommunicationManager.java:2468)
com.vaadin.server.AbstractCommunicationManager.handleBrowserDetailsRequest(AbstractCommunicationManager.java:2362)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:325)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

root cause

java.lang.ClassNotFoundException: com.google.gson.TypeAdapterFactory from BaseClassLoader@1a5da52{vfs:///D:/Projetos/GWT/.metadata/.plugins/org.jboss.ide.eclipse.as.core/jboss-6.1.0.Final_Runtime_Server1369766801891/deploy/grafico.war}
org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480)
java.lang.ClassLoader.loadClass(Unknown Source)
com.vaadin.addon.charts.Chart.(Chart.java:137)
com.vaadin.addon.charts.Chart.(Chart.java:154)
com.example.grafico.GraficoUI.init(GraficoUI.java:20)
com.vaadin.ui.UI.doInit(UI.java:529)
com.vaadin.server.AbstractCommunicationManager.getBrowserDetailsUI(AbstractCommunicationManager.java:2468)
com.vaadin.server.AbstractCommunicationManager.handleBrowserDetailsRequest(AbstractCommunicationManager.java:2362)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:325)
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

note The full stack trace of the root cause is available in the JBoss Web/3.0.0-CR2 logs.


JBoss Web/3.0.0-CR2

[/u]

with that code

[u]

package com.example.grafico;

import com.vaadin.addon.charts.Chart;
import com.vaadin.addon.charts.model.ChartType;
import com.vaadin.addon.charts.model.Configuration;
import com.vaadin.addon.charts.model.ListSeries;
import com.vaadin.addon.charts.model.Marker;
import com.vaadin.addon.charts.model.PlotOptionsLine;
import com.vaadin.addon.charts.model.XAxis;
import com.vaadin.addon.charts.model.YAxis;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings(“serial”)
public class GraficoUI extends UI {

@Override
protected void init(VaadinRequest request) {
	final VerticalLayout layout = new VerticalLayout();
	layout.setMargin(true);
	setContent(layout);
	layout.addComponent(new Label("Thank you for clicking"));
	
	Chart chart = new Chart(ChartType.COLUMN);
	chart.setWidth("300px");
	chart.setHeight("300px");
	
	Configuration conf = new Configuration();
	conf.setTitle("Reinder");
	conf.setSubTitle("no one");
	
	PlotOptionsLine plotOptions = new PlotOptionsLine();
	plotOptions.setMarker(new Marker(false));
	conf.setPlotOptions(plotOptions);
	
	ListSeries series = new ListSeries("Diameter");
	series.setData(4900, 12100, 12800, 6800, 14300, 125000, 51100, 49500);
	conf.addSeries(series);
	
	XAxis xAxis = new XAxis();
	xAxis.setCategories("Mercury", "Venus", "Earth",
			             "Mars", "Jupiter", "Saturn", "Uranus", "Neptune");
	xAxis.setTitle("P)lanet");
	conf.addxAxis(xAxis);
	
	YAxis yAxis = new YAxis();
	yAxis.setTitle("Diameter");
	yAxis.getLabels().setFormatter("function() {return Math.floor(this.value/1000) + \'Mm\';}");
	yAxis.getLabels().setStep(2);
	conf.addyAxis(yAxis);
	
}

}

[/u]

Please Help me.

Hi,

You are missing GSON library. With sane dependency management system like Maven you should get it automatically. Else you can copy it from the zip packages lib directory or download it from gson site.

cheers,
matti