use of com.vaadin.flow.component.charts.model.ListSeries in project flow-components by vaadin.
the class GaugeWithDualAxes method initDemo.
@Override
public void initDemo() {
// NOSONAR
final Random random = new Random(0);
final Chart chart = new Chart();
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.GAUGE);
configuration.setTitle("Speedometer with dual axes");
configuration.getChart().setWidth(500);
configuration.getPane().setStartAngle(-150);
configuration.getPane().setEndAngle(150);
YAxis yAxis = new YAxis();
yAxis.setClassName("kmh");
yAxis.setMin(0);
yAxis.setMax(200);
yAxis.setOffset(-25);
Labels labels = new Labels();
labels.setDistance(-20);
labels.setRotation("auto");
yAxis.setLabels(labels);
yAxis.setTickLength(5);
yAxis.setMinorTickLength(5);
yAxis.setEndOnTick(false);
YAxis yAxis2 = new YAxis();
yAxis2.setClassName("mph");
yAxis2.setMin(0);
yAxis2.setMax(124);
yAxis2.setOffset(-20);
labels = new Labels();
labels.setDistance(12);
labels.setRotation("auto");
yAxis2.setLabels(labels);
yAxis2.setTickPosition(TickPosition.OUTSIDE);
yAxis2.setMinorTickPosition(TickPosition.OUTSIDE);
yAxis2.setTickLength(5);
yAxis2.setMinorTickLength(5);
yAxis2.setEndOnTick(false);
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 class=\"kmh\">'+ this.y + ' km/h</span><br/>' + '<span class=\"mph\">' + Math.round(this.y * 0.621) + ' mph</span>';}");
plotOptionsGauge.setTooltip(new SeriesTooltip());
plotOptionsGauge.getTooltip().setValueSuffix(" km/h");
series.setPlotOptions(plotOptionsGauge);
configuration.addSeries(series);
runWhileAttached(chart, () -> {
Integer oldValue = series.getData()[0].intValue();
Integer newValue = (int) (oldValue + (random.nextDouble() - 0.5) * 20.0);
series.updatePoint(0, newValue);
}, 5000, 12000);
chart.drawChart();
add(chart);
}
use of com.vaadin.flow.component.charts.model.ListSeries in project flow-components by vaadin.
the class AreaChart method initDemo.
@Override
public void initDemo() {
final Chart chart = new Chart();
Configuration configuration = chart.getConfiguration();
configuration.setTitle("First Chart for Flow");
chart.getConfiguration().getChart().setType(ChartType.AREA);
add(chart);
configuration.addSeries(new ListSeries("Tokyo", 20, 12, 34, 23, 65, 8, 4, 7, 76, 19, 20, 8));
configuration.addSeries(new ListSeries("Miami", 34, 29, 23, 65, 8, 4, 7, 7, 59, 8, 9, 19));
XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
configuration.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
y.setTitle("Rainfall (mm)");
configuration.addyAxis(y);
NativeButton changeTitleButton = new NativeButton();
changeTitleButton.setId("change_title");
changeTitleButton.setText("Change title");
changeTitleButton.addClickListener(e -> {
configuration.setTitle("First Chart for Flow - title changed");
chart.drawChart();
});
add(changeTitleButton);
}
use of com.vaadin.flow.component.charts.model.ListSeries in project flow-components by vaadin.
the class BarChart method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart();
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Historic World Population by Region");
configuration.setSubTitle("Source: <a href=\"https://en.wikipedia.org/wiki/World_population\">Wikipedia.org</a>");
chart.getConfiguration().getChart().setType(ChartType.BAR);
configuration.addSeries(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
configuration.addSeries(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
configuration.addSeries(new ListSeries("Year 2000", 814, 841, 3714, 727, 31));
configuration.addSeries(new ListSeries("Year 2016", 1216, 1001, 4436, 738, 40));
XAxis x = new XAxis();
x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
configuration.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
AxisTitle yTitle = new AxisTitle();
yTitle.setText("Population (millions)");
yTitle.setAlign(VerticalAlign.HIGH);
y.setTitle(yTitle);
configuration.addyAxis(y);
Tooltip tooltip = new Tooltip();
tooltip.setValueSuffix(" millions");
configuration.setTooltip(tooltip);
PlotOptionsBar plotOptions = new PlotOptionsBar();
DataLabels dataLabels = new DataLabels();
dataLabels.setEnabled(true);
plotOptions.setDataLabels(dataLabels);
configuration.setPlotOptions(plotOptions);
add(chart);
}
use of com.vaadin.flow.component.charts.model.ListSeries in project flow-components by vaadin.
the class SVGGeneratorTest method createAreaChartConfiguration.
private Configuration createAreaChartConfiguration() {
Configuration configuration = new Configuration();
configuration.setTitle("First Chart for Flow");
configuration.getChart().setType(ChartType.AREA);
Tooltip tooltip = configuration.getTooltip();
tooltip.setEnabled(true);
tooltip.setShared(true);
PlotOptionsSeries options = new PlotOptionsSeries();
options.setPointStart(0);
options.setPointIntervalUnit(IntervalUnit.DAY);
configuration.setPlotOptions(options);
configuration.addSeries(new ListSeries("Tokyo", 20, 12, 34, 23, 65, 8, 4, 7, 76, 19, 20, 8));
configuration.addSeries(new ListSeries("Miami", 34, 29, 23, 65, 8, 4, 7, 7, 59, 8, 9, 19));
XAxis x = new XAxis();
x.setType(AxisType.DATETIME);
x.getLabels().setFormat("{value:%a}");
configuration.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
y.setTitle("Rainfall (mm)");
configuration.addyAxis(y);
return configuration;
}
use of com.vaadin.flow.component.charts.model.ListSeries in project flow-components by vaadin.
the class ConfigurationTest method configurationSetSeriesWithArraysAsListTest.
@Test(expected = Test.None.class)
public void configurationSetSeriesWithArraysAsListTest() {
Configuration conf = new Configuration();
conf.setSeries(Arrays.asList(new ListSeries()));
conf.addSeries(new ListSeries());
assertEquals(conf.getSeries().size(), 2);
}
Aggregations