use of com.vaadin.addon.charts.model.Hover in project charts by vaadin.
the class SplineWithPlotBandRemoveFunctionality method getChart.
@SuppressWarnings("deprecation")
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Wind speed during two days");
configuration.getSubTitle().setText("October 6th and 7th 2009 at two locations in Vik i Sogn, Norway");
configuration.getxAxis().setType(AxisType.DATETIME);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Wind speed (m/s)"));
yAxis.setMin(0);
yAxis.setMinorGridLineWidth(0);
yAxis.setGridLineWidth(0);
// disable alternate grid color from Vaadin theme, disturbs
// demonstrating plotbands
yAxis.setAlternateGridColor(TRANSPARENT);
createPlotBand(yAxis);
configuration.getTooltip().setFormatter("Highcharts.dateFormat('%e. %b %Y, %H:00', this.x) +': '+ this.y +' m/s'");
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
configuration.setPlotOptions(plotOptions);
plotOptions.setMarker(new Marker(false));
plotOptions.getMarker().setLineWidth(4);
plotOptions.getMarker().setSymbol(MarkerSymbolEnum.CIRCLE);
States states = new States();
Hover hover = new Hover(true);
hover.setRadius(5);
hover.setLineWidth(1);
states.setHover(hover);
plotOptions.getMarker().setStates(states);
plotOptions.setPointInterval(ONE_HOUR);
LocalDate date = LocalDate.of(2009, 9, 6);
plotOptions.setPointStart(date.atStartOfDay().toInstant(ZoneOffset.UTC));
ListSeries ls = new ListSeries();
ls.setName("Hestavollane");
ls.setData(4.3, 5.1, 4.3, 5.2, 5.4, 4.7, 3.5, 4.1, 5.6, 7.4, 6.9, 7.1, 7.9, 7.9, 7.5, 6.7, 7.7, 7.7, 7.4, 7.0, 7.1, 5.8, 5.9, 7.4, 8.2, 8.5, 9.4, 8.1, 10.9, 10.4, 10.9, 12.4, 12.1, 9.5, 7.5, 7.1, 7.5, 8.1, 6.8, 3.4, 2.1, 1.9, 2.8, 2.9, 1.3, 4.4, 4.2, 3.0, 3.0);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("Voll");
ls.setData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.0, 0.3, 0.0, 0.0, 0.4, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6, 1.2, 1.7, 0.7, 2.9, 4.1, 2.6, 3.7, 3.9, 1.7, 2.3, 3.0, 3.3, 4.8, 5.0, 4.8, 5.0, 3.2, 2.0, 0.9, 0.4, 0.3, 0.5, 0.4);
configuration.addSeries(ls);
chart.drawChart(configuration);
final Button removePlotBand = new Button("Remove PlotBands");
removePlotBand.setId("vaadin-button");
removePlotBand.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
YAxis axis = chart.getConfiguration().getyAxis();
if (axis.getPlotBands() == null || axis.getPlotBands().length == 0) {
createPlotBand(chart.getConfiguration().getyAxis());
removePlotBand.setCaption("Remove PlotBands");
} else {
chart.getConfiguration().getyAxis().setPlotBands(new PlotBand[] {});
removePlotBand.setCaption("Restore PlotBands");
}
chart.drawChart(configuration);
}
});
VerticalLayout verticalLayout = new VerticalLayout(removePlotBand, chart);
verticalLayout.setSpacing(false);
verticalLayout.setMargin(false);
return verticalLayout;
}
Aggregations