PDA

View Full Version : Hide chart legend while series is empty



kpiskunov
7 Dec 2011, 6:49 AM
Hi,

I am trying to configure line chart and bind it to store. It works but the only problem is that chart displays legend even before first point is added to the store.

Is there any way to hide legend for series that don't have any data yet?



final Chart<SimpleData> chart = new Chart<SimpleData>();
chart.setTitle("Cell Value");
chart.bindStore(store);
chart.setChartShadow(true);

NumericAxis<SimpleData> axis = new NumericAxis<SimpleData>();
axis.setPosition(Position.LEFT);
axis.addField(DATA_ACCESS.data1());
axis.setLength(100);
axis.setDisplayGrid(true);
axis.setMinimum(0);
axis.setMaximum(100);
chart.addAxis(axis);

CategoryAxis<SimpleData, String> catAxis = new CategoryAxis<SimpleData, String>();
catAxis.setPosition(Position.BOTTOM);
catAxis.setField(DATA_ACCESS.name());
catAxis.setDisplayGrid(true);
catAxis.setLabelProvider(new LabelProvider<String>()
{
@Override
public String getLabel(final String item)
{
return item;
}
});
chart.addAxis(catAxis);

LineSeries<SimpleData> series = new LineSeries<SimpleData>();
series.setYAxisPosition(Position.LEFT);
series.setYField(DATA_ACCESS.data1());
series.setStroke(RGB.RED);
series.setShowMarkers(true);
series.setMarkerType(Shape.CIRCLE);
series.setMarkerSize(3);
series.setMarkerColor(RGB.RED);
chart.addSeries(series);

Legend<SimpleData> legend = new Legend<SimpleData>();
legend.setPosition(Position.RIGHT);
legend.setItemHighlighting(true);
legend.setItemHiding(true);
chart.setLegend(legend);

BrendanC
8 Dec 2011, 2:02 PM
Yes the option is configured from the series itself. For example you would use series.setShownInLegend(false); then you could set it to true when loading your data.