use of com.vaadin.addon.charts.model.ListSeries 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;
}
use of com.vaadin.addon.charts.model.ListSeries in project charts by vaadin.
the class GaugeWithDualAxes method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.GAUGE);
configuration.getChart().setAlignTicks(false);
configuration.getChart().setPlotBackgroundColor(null);
configuration.getChart().setPlotBackgroundImage(null);
configuration.getChart().setPlotBorderWidth(0);
configuration.getChart().setPlotShadow(false);
configuration.setTitle("Speedometer with dual axes");
configuration.getPane().setStartAngle(-150);
configuration.getPane().setEndAngle(150);
YAxis yAxis = new YAxis();
yAxis.setMin(0);
yAxis.setMax(200);
yAxis.setLineColor(new SolidColor("#339"));
yAxis.setTickColor(new SolidColor("#339"));
yAxis.setMinorTickColor(new SolidColor("#339"));
yAxis.setOffset(-25);
yAxis.setLineWidth(2);
Labels labels = new Labels();
labels.setDistance(-20);
labels.setRotationPerpendicular();
labels.setRotation("auto");
yAxis.setLabels(labels);
yAxis.setTickLength(5);
yAxis.setMinorTickLength(5);
yAxis.setEndOnTick(false);
YAxis yAxis2 = new YAxis();
yAxis2.setMin(0);
yAxis2.setMax(124);
yAxis2.setLineColor(new SolidColor("#933"));
yAxis2.setTickColor(new SolidColor("#933"));
yAxis2.setMinorTickColor(new SolidColor("#933"));
yAxis2.setOffset(-20);
yAxis2.setLineWidth(2);
labels = new Labels();
labels.setDistance(12);
labels.setRotationPerpendicular();
yAxis2.setLabels(labels);
yAxis2.setTickLength(5);
yAxis2.setMinorTickLength(5);
yAxis2.setEndOnTick(false);
yAxis2.setTickPosition(TickPosition.OUTSIDE);
yAxis2.setMinorTickPosition(TickPosition.OUTSIDE);
configuration.addyAxis(yAxis);
configuration.addyAxis(yAxis2);
final ListSeries series = new ListSeries("Speed", 80);
PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
plotOptionsGauge.setDataLabels(new DataLabels());
plotOptionsGauge.getDataLabels().setFormatter("function() {return '<span style=\"color:#339\">'+ this.y + ' km/h</span><br/>' + '<span style=\"color:#933\">' + Math.round(this.y * 0.621) + ' mph</span>';}");
GradientColor gradient = GradientColor.createLinear(0, 0, 0, 1);
gradient.addColorStop(0, new SolidColor("#DDD"));
gradient.addColorStop(1, new SolidColor("#FFF"));
plotOptionsGauge.getDataLabels().setBackgroundColor(gradient);
plotOptionsGauge.setTooltip(new SeriesTooltip());
plotOptionsGauge.getTooltip().setValueSuffix(" km/h");
series.setPlotOptions(plotOptionsGauge);
configuration.setSeries(series);
runWhileAttached(chart, new Runnable() {
Random r = new Random(0);
@Override
public void run() {
Integer oldValue = series.getData()[0].intValue();
Integer newValue = (int) (oldValue + (r.nextDouble() - 0.5) * 20.0);
series.updatePoint(0, newValue);
}
}, 5000, 12000);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.ListSeries in project charts by vaadin.
the class JSAndJavaApi method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setJsonConfig(JSON_CONF);
Configuration conf = chart.getConfiguration();
conf.setSeries(new ListSeries(getRawData()));
return chart;
}
use of com.vaadin.addon.charts.model.ListSeries in project charts by vaadin.
the class LegendMarginTestUI method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.LINE);
chart.setHeight("450px");
chart.setWidth("100%");
chart.getConfiguration().addSeries(new ListSeries(1, 2, 3));
Legend legend = chart.getConfiguration().getLegend();
legend.setMargin(100);
return chart;
}
use of com.vaadin.addon.charts.model.ListSeries in project charts by vaadin.
the class PartialUpdateConflicts method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setHeight("200px");
final ListSeries listSeries = new ListSeries(data);
chart.getConfiguration().addSeries(listSeries);
Button button = new Button("Do stuff", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
listSeries.addData(100, true, true);
ArrayUtils.reverse(data);
chart.getConfiguration().setSeries(new ListSeries(data));
chart.drawChart();
}
});
button.setId("b1");
final Chart chart2 = new Chart();
chart2.setHeight("200px");
final DataSeries ds = new DataSeries();
int i = 0;
for (Integer value : data) {
ds.add(new DataSeriesItem(i++, value));
}
chart2.getConfiguration().addSeries(ds);
Button button2 = new Button("Do stuff DataSeries", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
final DataSeriesItem dataSeriesItem = new DataSeriesItem(ds.size(), new Random().nextInt(10));
ds.add(dataSeriesItem);
ArrayUtils.reverse(data);
chart2.getConfiguration().setSeries(new ListSeries(data));
chart2.drawChart();
}
});
button2.setId("b2");
VerticalLayout verticalLayout = new VerticalLayout(chart, button, chart2, button2);
verticalLayout.setSpacing(false);
verticalLayout.setMargin(false);
return verticalLayout;
}
Aggregations