use of com.vaadin.addon.charts.LegendItemClickListener in project charts by vaadin.
the class ServerSideEvents method addEventListeners.
private Layout addEventListeners() {
eventListeners = new VerticalLayout();
eventListeners.setCaption("Event listeners:");
final ChartClickListener listener = new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Chart click", "ChartClick", new ListenerToggle() {
@Override
public void add() {
chart.addChartClickListener(listener);
}
@Override
public void remove() {
chart.removeChartClickListener(listener);
}
});
final PointClickListener pcListener = new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Point click", "PointClick", new ListenerToggle() {
@Override
public void add() {
chart.addPointClickListener(pcListener);
}
@Override
public void remove() {
chart.removePointClickListener(pcListener);
}
});
final CheckboxClickListener cbListener = new CheckboxClickListener() {
@Override
public void onClick(CheckboxClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Checkbox click", "CheckboxClick", new ListenerToggle() {
@Override
public void add() {
chart.addCheckBoxClickListener(cbListener);
}
@Override
public void remove() {
chart.removeCheckBoxClickListener(cbListener);
}
});
final LegendItemClickListener legendItemListener = new LegendItemClickListener() {
@Override
public void onClick(LegendItemClickEvent event) {
logEvent(event);
}
};
addToggleForListener("Legend item click", "LegendItemClick", new ListenerToggle() {
@Override
public void add() {
chart.addLegendItemClickListener(legendItemListener);
visibilityToggling.setValue(true);
}
@Override
public void remove() {
chart.removeLegendItemClickListener(legendItemListener);
}
});
final SeriesHideListener hideListener = new SeriesHideListener() {
@Override
public void onHide(SeriesHideEvent event) {
logEvent(event);
}
};
addToggleForListener("Series hide", "SeriesHide", new ListenerToggle() {
@Override
public void add() {
chart.addSeriesHideListener(hideListener);
}
@Override
public void remove() {
chart.removeSeriesHideListener(hideListener);
}
});
final SeriesShowListener show = new SeriesShowListener() {
@Override
public void onShow(SeriesShowEvent event) {
logEvent(event);
}
};
addToggleForListener("Series show", "SeriesShow", new ListenerToggle() {
@Override
public void add() {
chart.addSeriesShowListener(show);
}
@Override
public void remove() {
chart.removeSeriesShowListener(show);
}
});
final XAxesExtremesChangeListener xaxesListener = new XAxesExtremesChangeListener() {
@Override
public void onXAxesExtremesChange(XAxesExtremesChangeEvent event) {
logEvent(event);
}
};
addToggleForListener("XAxes extremes change", "XAxesExtremes", new ListenerToggle() {
@Override
public void add() {
chart.addXAxesExtremesChangeListener(xaxesListener);
}
@Override
public void remove() {
chart.removeXAxesExtremesChangeListener(xaxesListener);
}
});
final YAxesExtremesChangeListener yaxesListener = new YAxesExtremesChangeListener() {
@Override
public void onYAxesExtremesChange(YAxesExtremesChangeEvent event) {
logEvent(event);
}
};
addToggleForListener("Y axes extremes change", "YAxesExtremes", new ListenerToggle() {
@Override
public void add() {
chart.addYAxesExtremesChangeListener(yaxesListener);
}
@Override
public void remove() {
chart.removeYAxesExtremesChangeListener(yaxesListener);
}
});
final PointSelectListener selectListener = new PointSelectListener() {
@Override
public void onSelect(PointSelectEvent event) {
logEvent(event);
}
};
addToggleForListener("Point select", "PointSelect", new ListenerToggle() {
@Override
public void add() {
chart.addPointSelectListener(selectListener);
}
@Override
public void remove() {
chart.removePointSelectListener(selectListener);
}
});
final PointUnselectListener unselectListener = new PointUnselectListener() {
@Override
public void onUnselect(PointUnselectEvent event) {
logEvent(event);
}
};
addToggleForListener("Point unselect", "PointUnselect", new ListenerToggle() {
@Override
public void add() {
chart.addPointUnselectListener(unselectListener);
}
@Override
public void remove() {
chart.removePointUnselectListener(unselectListener);
}
});
return eventListeners;
}
use of com.vaadin.addon.charts.LegendItemClickListener in project charts by vaadin.
the class ToggledSeriesVisibility method getChart.
@Override
protected Component getChart() {
chart = new Chart(ChartType.COLUMN);
Configuration conf = chart.getConfiguration();
conf.setTitle("Monthly Average Rainfall");
conf.setSubTitle("Source: WorldClimate.com");
XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
conf.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
y.setTitle("Rainfall (mm)");
conf.addyAxis(y);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setBackgroundColor(new SolidColor("#FFFFFF"));
legend.setAlign(HorizontalAlign.LEFT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(100);
legend.setY(70);
legend.setFloating(true);
legend.setShadow(true);
conf.setLegend(legend);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.x +': '+ this.y +' mm'");
conf.setTooltip(tooltip);
PlotOptionsColumn plot = new PlotOptionsColumn();
plot.setPointPadding(0.2);
plot.setBorderWidth(0);
conf.addSeries(tokyo);
conf.addSeries(newYork);
conf.addSeries(berlin);
conf.addSeries(london);
chart.addLegendItemClickListener(new LegendItemClickListener() {
@Override
public void onClick(LegendItemClickEvent event) {
/*
* Visibility of the series is also toggled from legend clicks
* by default. Still developers might wish to override this
* behavior if the visibility is also controlled by other
* components like here or if e.g. multiple charts are bound
* together (hiding series in one chart should hide related data
* in other chart as well).
*/
ListSeries series = (ListSeries) event.getSeries();
/*
* Toggle checked in option group. As a side effect (via value
* change listener, see setup method) the visibility will change
* in the chart as well.
*/
if (series.isVisible()) {
checkBoxGroup.deselect(series);
} else {
checkBoxGroup.select(series);
}
}
});
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.LegendItemClickListener in project charts by vaadin.
the class PieWithLegend method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.PIE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Browser market shares at a specific website, 2010");
Tooltip tooltip = new Tooltip();
tooltip.setValueDecimals(1);
tooltip.setPointFormat("{series.name}: <b>{point.percentage}%</b>");
conf.setTooltip(tooltip);
PlotOptionsPie plotOptions = new PlotOptionsPie();
plotOptions.setAllowPointSelect(true);
plotOptions.setCursor(Cursor.POINTER);
plotOptions.setShowInLegend(true);
conf.setPlotOptions(plotOptions);
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.addLegendItemClickListener(new LegendItemClickListener() {
@Override
public void onClick(LegendItemClickEvent event) {
Notification.show("Legend item click" + " : " + event.getSeriesItemIndex() + " : " + ((DataSeries) event.getSeries()).get(event.getSeriesItemIndex()).getName());
}
});
chart.drawChart(conf);
return chart;
}
Aggregations