Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin Pie Charts: determining if DataSeriesItem is "sliced or not sliced"
Hi,
is there a way to determine if some DataSeriesItem is sliced/not sliced on PointClickEvent?
Here's a slightly modified sample taken directly from http://demo.vaadin.com/charts/#PieChart:
package com.example.testcharts;
import javax.servlet.annotation.WebServlet;
import com.vaadin.addon.charts.Chart;
import com.vaadin.addon.charts.PointClickEvent;
import com.vaadin.addon.charts.PointClickListener;
import com.vaadin.addon.charts.model.ChartType;
import com.vaadin.addon.charts.model.Configuration;
import com.vaadin.addon.charts.model.Cursor;
import com.vaadin.addon.charts.model.DataSeries;
import com.vaadin.addon.charts.model.DataSeriesItem;
import com.vaadin.addon.charts.model.Labels;
import com.vaadin.addon.charts.model.PlotOptionsPie;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
@Theme("testcharts")
public class TestchartsUI extends UI {
@Override
public String getDescription() {
return "Pie chart";
}
protected Component getChart() {
Component ret = createChart();
ret.setWidth("100%");
ret.setHeight("450px");
return ret;
}
public static Chart createChart() {
Chart chart = new Chart(ChartType.PIE);
chart.setImmediate(true);
Configuration conf = chart.getConfiguration();
conf.setTitle("Browser market shares at a specific website, 2010");
PlotOptionsPie plotOptions = new PlotOptionsPie();
plotOptions.setCursor(Cursor.POINTER);
plotOptions.setAllowPointSelect(true);
Labels dataLabels = new Labels();
dataLabels.setEnabled(true);
dataLabels.setFormatter("''+ this.point.name +': '+ this.percentage +' %'");
plotOptions.setDataLabels(dataLabels);
conf.setPlotOptions(plotOptions);
final DataSeries series = new DataSeries();
series.add(new DataSeriesItem("Firefox", 45.0));
series.add(new DataSeriesItem("IE", 26.8));
DataSeriesItem chrome = new DataSeriesItem("Chrome", 12.8);
// chrome.setSliced(true);
// chrome.setSelected(true);
series.add(chrome);
series.add(new DataSeriesItem("Safari", 8.5));
series.add(new DataSeriesItem("Opera", 6.2));
series.add(new DataSeriesItem("Others", 0.7));
conf.setSeries(series);
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
[b]// Notification.show("Click: " +
DataSeries series = (DataSeries) event.getSeries();
DataSeriesItem item = series.get(event.getPointIndex());
System.out.println(">>> PointClickListener");
System.out.println(">>> data series item: " + item);
System.out.println(">>> is sliced = " + item.getSliced());[/b]
}
});
chart.drawChart(conf);
return chart;
}
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = TestchartsUI.class, widgetset = "com.example.testcharts.widgetset.TestchartsWidgetset")
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
System.setProperty("vaadin.charts.developer.license", "ec7cf490-aa3e-429b-90fd-d31a95cefa7e");
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
layout.addComponent(getChart());
}
}
According to
plotOptions.setAllowPointSelect(true);
when some point is being clicked the corresponding DataSeriesItem changes to sliced/not sliced states back and forth.
In the "onClick" method within the PointClickListener one needs to determine the state to which the clicked DataSeriesItem has been set: sliced or not sliced.
If DataSeriesItem.getSliced() method is being used with Vaadin Charts 2.1.0, 2.1.1 you get an exception: java.lang.NullPointerException at com.vaadin.addon.charts.model.AbstractSeriesItem.getSliced(AbstractSeriesItem.java:122)
With Vaadin Charts 1.1.9 no exception occurs, but getSliced() always returns false regardless of the point's actual state.
Probably inside the onClick method the point's "sliced" state has not been set yet for the moment. Any workarounds?
Thanks!