use of com.vaadin.flow.component.charts.model.PlotOptionsSpline in project flow-components by vaadin.
the class MultipleAxes method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.getChart().setZoomType(Dimension.XY);
conf.setTitle("Average Monthly Weather Data for Tokyo");
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 y1 = new YAxis();
y1.setShowEmpty(false);
y1.setTitle(new AxisTitle("Temperature"));
Labels labels = new Labels();
labels.setFormatter("return this.value +'°C'");
y1.setLabels(labels);
y1.setOpposite(true);
y1.setClassName("y1");
conf.addyAxis(y1);
YAxis y2 = new YAxis();
y2.setShowEmpty(false);
y2.setTitle(new AxisTitle("Rainfall"));
labels = new Labels();
labels.setFormatter("return this.value +' mm'");
y2.setLabels(labels);
y2.setClassName("y2");
conf.addyAxis(y2);
YAxis y3 = new YAxis();
y3.setShowEmpty(false);
y3.setTitle(new AxisTitle("Sea-Level Pressure"));
labels = new Labels();
labels.setFormatter("return this.value +' mb'");
y3.setLabels(labels);
y3.setOpposite(true);
y3.setClassName("y3");
conf.addyAxis(y3);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("function() { " + "var unit = { 'Rainfall': 'mm', 'Temperature': '°C', 'Sea-Level Pressure': 'mb' }[this.series.name];" + "return ''+ this.x +': '+ this.y +' '+ unit; }");
conf.setTooltip(tooltip);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setX(120);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setY(80);
legend.setFloating(true);
conf.setLegend(legend);
DataSeries series = new DataSeries();
PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
series.setPlotOptions(plotOptionsColumn);
series.setName("Rainfall");
series.setyAxis(1);
series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
conf.addSeries(series);
series = new DataSeries();
PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
series.setPlotOptions(plotOptionsSpline);
series.setName("Sea-Level Pressure");
series.setyAxis(2);
series.setData(1016, 1016, 1015.9, 1015.5, 1012.3, 1009.5, 1009.6, 1010.2, 1013.1, 1016.9, 1018.2, 1016.7);
conf.addSeries(series);
series = new DataSeries();
plotOptionsSpline = new PlotOptionsSpline();
series.setPlotOptions(plotOptionsSpline);
series.setName("Temperature");
series.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
conf.addSeries(series);
add(chart);
}
use of com.vaadin.flow.component.charts.model.PlotOptionsSpline in project flow-components by vaadin.
the class ColumnLineAndPie method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.setTitle("Combined Chart");
conf.setExporting(true);
XAxis x = new XAxis();
x.setCategories(new String[] { "Apples", "Oranges", "Pears", "Bananas", "Plums" });
conf.addxAxis(x);
Style labelStyle = new Style();
labelStyle.setTop("8px");
labelStyle.setLeft("40px");
conf.setLabels(new HTMLLabels(labelStyle, new HTMLLabelItem("Total fruit consumption")));
DataSeries series = new DataSeries();
PlotOptionsColumn plotOptions = new PlotOptionsColumn();
series.setPlotOptions(plotOptions);
series.setName("Jane");
series.setData(3, 2, 1, 3, 4);
conf.addSeries(series);
series = new DataSeries();
plotOptions = new PlotOptionsColumn();
series.setPlotOptions(plotOptions);
series.setName("John");
series.setData(2, 3, 5, 7, 6);
conf.addSeries(series);
series = new DataSeries();
plotOptions = new PlotOptionsColumn();
series.setPlotOptions(plotOptions);
series.setName("Joe");
series.setData(4, 3, 3, 9, 0);
conf.addSeries(series);
series = new DataSeries();
PlotOptionsSpline splinePlotOptions = new PlotOptionsSpline();
series.setPlotOptions(splinePlotOptions);
series.setName("Average");
series.setData(3, 2.67, 3, 6.33, 3.33);
conf.addSeries(series);
series = new DataSeries();
series.setPlotOptions(new PlotOptionsPie());
series.setName("Total consumption");
DataSeriesItem item = new DataSeriesItem("Jane", 13);
series.add(item);
item = new DataSeriesItem("John", 23);
series.add(item);
item = new DataSeriesItem("Joe", 19);
series.add(item);
PlotOptionsPie plotOptionsPie = new PlotOptionsPie();
plotOptionsPie.setSize("100px");
plotOptionsPie.setCenter("100px", "80px");
plotOptionsPie.setShowInLegend(false);
series.setPlotOptions(plotOptionsPie);
conf.addSeries(series);
add(chart);
}
use of com.vaadin.flow.component.charts.model.PlotOptionsSpline in project flow-components by vaadin.
the class SplineUpdatingEachSecond method initDemo.
@Override
public void initDemo() {
// NOSONAR
final Random random = new Random();
final Chart chart = new Chart();
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Live random data");
XAxis xAxis = configuration.getxAxis();
xAxis.setType(AxisType.DATETIME);
xAxis.setTickPixelInterval(150);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
configuration.getTooltip().setEnabled(false);
configuration.getLegend().setEnabled(false);
final DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Random data");
for (int i = -19; i <= 0; i++) {
series.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
}
configuration.setSeries(series);
runWhileAttached(chart, () -> {
final long x = System.currentTimeMillis();
final double y = random.nextDouble();
series.add(new DataSeriesItem(x, y), true, true);
}, 1000, 1000);
add(chart);
}
Aggregations