use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.
the class DynamicExtremes method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart();
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.LINE);
configuration.getChart().setMarginRight(130);
configuration.getChart().setMarginBottom(25);
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis yAxis = configuration.getyAxis();
yAxis.setMin(-10d);
yAxis.setMax(30d);
yAxis.setTitle(new AxisTitle("Temperature (°C)"));
yAxis.getTitle().setAlign(VerticalAlign.HIGH);
configuration.getTooltip().setFormatter("return '<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setDataLabels(new DataLabels(true));
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-10d);
legend.setY(100d);
ListSeries ls = new ListSeries();
ls.setName("Tokyo");
ls.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);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("New York");
ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("Berlin");
ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0);
configuration.addSeries(ls);
ls = new ListSeries();
ls.setName("London");
ls.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
configuration.addSeries(ls);
NativeButton toggleExtremesButton = new NativeButton("Toggle extremes", e -> {
if (setExtremes) {
chart.getConfiguration().getyAxes().getAxis(0).setExtremes(10, 15);
} else {
chart.getConfiguration().resetZoom();
}
setExtremes = !setExtremes;
});
toggleExtremesButton.setId("toggleExtremesButton");
add(chart, toggleExtremesButton);
}
use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.
the class ServerSideEvents method initDemo.
@Override
public void initDemo() {
historyLayout = new OrderedList();
historyLayout.setId("history");
chart = new Chart();
chart.setId("chart");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setWidth(500);
configuration.getChart().setType(ChartType.SCATTER);
configuration.getTitle().setText("Test server side events.");
configuration.getSubTitle().setText("When an event occurs, the details are shown below the chart");
configuration.setExporting(true);
configuration.getChart().setAnimation(false);
configuration.getChart().setZoomType(Dimension.XY);
configuration.getAccessibility().setEnabled(false);
XAxis xAxis = configuration.getxAxis();
xAxis.setMinPadding(0.2);
xAxis.setMaxPadding(0.2);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
PlotLine plotline = new PlotLine();
plotline.setValue(0);
plotline.setWidth(1);
plotline.setColor(new SolidColor("#808080"));
yAxis.setPlotLines(plotline);
yAxis.setMinPadding(0.2);
yAxis.setMaxPadding(0.2);
YAxis yAxis1 = new YAxis();
yAxis1.setTitle("Another axis");
yAxis1.setOpposite(true);
configuration.addyAxis(yAxis1);
PlotOptionsSeries opt = new PlotOptionsSeries();
opt.setShowCheckbox(true);
opt.setAllowPointSelect(true);
configuration.setPlotOptions(opt);
configuration.setTooltip(new Tooltip(false));
final DataSeries series1 = createDataSeries(0);
final DataSeries series2 = createDataSeries(20);
DataSeries series3 = createDataSeries(100);
series3.get(0).setY(105);
series3.get(3).setY(95);
series3.setName("Another axis");
series3.setyAxis(1);
DataSeriesItem firstDataPoint = series1.get(0);
firstDataPoint.setSelected(true);
configuration.setSeries(series1, series2, series3);
chart.addChartClickListener(this::logEvent);
chart.addPointClickListener(this::logEvent);
chart.addCheckBoxClickListener(this::logEvent);
chart.addSeriesLegendItemClickListener(this::logEvent);
chart.addSeriesHideListener(this::logEvent);
chart.addSeriesShowListener(this::logEvent);
chart.addPointSelectListener(this::logEvent);
chart.addPointUnselectListener(this::logEvent);
chart.addYAxesExtremesSetListener(this::logEvent);
chart.drawChart();
chart.setVisibilityTogglingDisabled(false);
VerticalLayout layout = new VerticalLayout();
layout.setId("master");
layout.add(createControls());
layout.add(new H2("Event History"), historyLayout);
add(chart, layout);
}
use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.
the class BasicLineWithCallouts method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart();
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.LINE);
configuration.getTitle().setText("CALLOUT: Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Temperature (°C)"));
configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setEnableMouseTracking(false);
configuration.setPlotOptions(plotOptions);
DataSeries ds = new DataSeries();
ds.setName("Tokyo");
ds.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);
DataLabels callout = new DataLabels(true);
callout.setShape(Shape.CALLOUT);
callout.setY(-12);
ds.get(5).setDataLabels(callout);
configuration.addSeries(ds);
ds = new DataSeries();
ds.setName("London");
ds.setData(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8);
ds.get(6).setDataLabels(callout);
configuration.addSeries(ds);
add(chart);
}
use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.
the class Line method initDemo.
@Override
public void initDemo() {
final Chart chart = new Chart();
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Solar Employment Growth by Sector, 2010-2016");
configuration.setSubTitle("Source: thesolarfoundation.com");
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle("Number of Employees");
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setVerticalAlign(VerticalAlign.MIDDLE);
legend.setAlign(HorizontalAlign.RIGHT);
PlotOptionsSeries plotOptionsSeries = new PlotOptionsSeries();
plotOptionsSeries.setPointStart(2010);
configuration.setPlotOptions(plotOptionsSeries);
configuration.addSeries(new ListSeries("Installation", 43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175));
configuration.addSeries(new ListSeries("Manufacturing", 24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434));
configuration.addSeries(new ListSeries("Sales & Distribution", 11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387));
configuration.addSeries(new ListSeries("Project Development", null, null, 7988, 12169, 15112, 22452, 34400, 34227));
configuration.addSeries(new ListSeries("Other", 12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111));
add(chart);
}
use of com.vaadin.flow.component.charts.model.Configuration in project flow-components by vaadin.
the class Scatter method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart(ChartType.SCATTER);
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Height Versus Weight of 507 Individuals by Gender");
configuration.setSubTitle("Source: Heinz 2003");
XAxis xAxis = configuration.getxAxis();
xAxis.setTitle("Height (cm)");
xAxis.setStartOnTick(true);
xAxis.setEndOnTick(true);
xAxis.setShowLastLabel(true);
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(100);
legend.setY(70);
legend.setFloating(true);
PlotOptionsScatter plotOptionsScatter = new PlotOptionsScatter();
SeriesTooltip scatterTooltip = plotOptionsScatter.getTooltip();
scatterTooltip.setHeaderFormat("<b>{series.name}</b><br>\",\"pointFormat\":\"{point.x} cm, {point.y} kg");
DataSeries femaleSeries = new DataSeries();
femaleSeries.setName("Female");
PlotOptionsScatter femalePlotOptions = new PlotOptionsScatter();
femalePlotOptions.setClassName("femaleSeries");
femaleSeries.setPlotOptions(femalePlotOptions);
Number[][] femaleData = getFemaleData();
for (int i = 0; i < femaleData.length; i++) {
DataSeriesItem item = new DataSeriesItem(femaleData[i][1], femaleData[i][0]);
femaleSeries.add(item);
}
configuration.addSeries(femaleSeries);
DataSeries maleSeries = new DataSeries();
maleSeries.setName("Male");
PlotOptionsScatter malePlotOptions = new PlotOptionsScatter();
malePlotOptions.setClassName("maleSeries");
maleSeries.setPlotOptions(malePlotOptions);
Number[][] maleData = getMaleData();
for (int i = 0; i < maleData.length; i++) {
DataSeriesItem item = new DataSeriesItem(maleData[i][1], maleData[i][0]);
maleSeries.add(item);
}
configuration.addSeries(maleSeries);
add(chart);
}
Aggregations