use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class Gauge 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");
configuration.getChart().setWidth(500);
Pane pane = configuration.getPane();
pane.setStartAngle(-150);
pane.setEndAngle(150);
YAxis yAxis = new YAxis();
yAxis.setTitle("km/h");
yAxis.setMin(0);
yAxis.setMax(200);
yAxis.setTickLength(10);
yAxis.setTickPixelInterval(30);
yAxis.setTickPosition(TickPosition.INSIDE);
yAxis.setMinorTickLength(10);
yAxis.setMinorTickInterval("auto");
yAxis.setMinorTickPosition(TickPosition.INSIDE);
Labels labels = new Labels();
labels.setStep(2);
labels.setRotation("auto");
yAxis.setLabels(labels);
PlotBand[] bands = new PlotBand[3];
bands[0] = new PlotBand();
bands[0].setFrom(0);
bands[0].setTo(120);
bands[0].setClassName("band-0");
bands[1] = new PlotBand();
bands[1].setFrom(120);
bands[1].setTo(160);
bands[1].setClassName("band-1");
bands[2] = new PlotBand();
bands[2].setFrom(160);
bands[2].setTo(200);
bands[2].setClassName("band-2");
yAxis.setPlotBands(bands);
configuration.addyAxis(yAxis);
final ListSeries series = new ListSeries("Speed", 89);
PlotOptionsGauge plotOptionsGauge = new PlotOptionsGauge();
SeriesTooltip tooltip = new SeriesTooltip();
tooltip.setValueSuffix(" km/h");
plotOptionsGauge.setTooltip(tooltip);
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);
add(chart);
}
use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class GlobalOptions method initDemo.
@Override
public void initDemo() {
List<Chart> charts = new ArrayList();
NativeButton changeTitleButton = new NativeButton();
changeTitleButton.setId("add_chart");
changeTitleButton.setText("Add chart");
changeTitleButton.addClickListener(e -> {
final Chart chart = new Chart();
Configuration configuration = chart.getConfiguration();
configuration.setTitle("First Chart for Flow");
chart.getConfiguration().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);
charts.add(chart);
add(chart);
});
add(changeTitleButton);
NativeButton changeLangButton = new NativeButton();
changeLangButton.setId("change_lang");
changeLangButton.setText("Change lang");
changeLangButton.addClickListener(e -> {
Lang lang = new Lang();
lang.setShortMonths(new String[] { "Tammi", "Helmi", "Maalis", "Huhti", "Touko", "Kesä", "Heinä", "Elo", "Syys", "Loka", "Marras", "Joulu" });
lang.setMonths(new String[] { "Tammikuu", "Helmikuu", "Maaliskuu", "Huhtikuu", "Toukokuu", "Kesäkuu", "Heinäkuu", "Elokuu", "Syyskuu", "Lokakuu", "Marraskuu", "Joulukuu" });
lang.setWeekdays(new String[] { "Sunnuntai", "Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai" });
lang.setShortWeekdays(new String[] { "su", "ma", "ti", "ke", "to", "pe", "la" });
ChartOptions.get().setLang(lang);
});
add(changeLangButton);
NativeButton changeThemeLightButton = new NativeButton();
changeThemeLightButton.setId("change_theme_light");
changeThemeLightButton.setText("Change theme light");
changeThemeLightButton.addClickListener(e -> {
ChartOptions.get().setTheme(new LumoLightTheme());
for (Chart chart : charts) {
chart.drawChart(true);
}
});
add(changeThemeLightButton);
NativeButton changeThemeDarkButton = new NativeButton();
changeThemeDarkButton.setId("change_theme_dark");
changeThemeDarkButton.setText("Change theme Dark");
changeThemeDarkButton.addClickListener(e -> {
ChartOptions.get().setTheme(new LumoDarkTheme());
for (Chart chart : charts) {
chart.drawChart(true);
}
});
add(changeThemeDarkButton);
}
use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class Xrange method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart(ChartType.XRANGE);
Configuration conf = chart.getConfiguration();
conf.setTitle("X-range");
conf.getxAxis().setType(AxisType.DATETIME);
conf.getyAxis().setTitle("");
conf.getyAxis().setCategories("Prototyping", "Development", "Testing");
conf.getyAxis().setReversed(true);
DataSeries series = new DataSeries();
series.setName("Project 1");
series.add(new DataSeriesItemXrange(getInstant(2014, 11, 21), getInstant(2014, 12, 2), 0, 0.25));
series.add(new DataSeriesItemXrange(getInstant(2014, 12, 2), getInstant(2014, 12, 5), 1));
series.add(new DataSeriesItemXrange(getInstant(2014, 12, 8), getInstant(2014, 12, 9), 2));
series.add(new DataSeriesItemXrange(getInstant(2014, 12, 9), getInstant(2014, 12, 19), 1));
series.add(new DataSeriesItemXrange(getInstant(2014, 12, 10), getInstant(2014, 12, 23), 2));
PlotOptionsXrange options = new PlotOptionsXrange();
options.setBorderColor(SolidColor.GRAY);
options.setPointWidth(20);
options.getDataLabels().setEnabled(true);
series.setPlotOptions(options);
conf.addSeries(series);
add(chart);
}
use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class PieWithLegend method initDemo.
@Override
public void initDemo() {
chart = new Chart(ChartType.PIE);
Configuration conf = chart.getConfiguration();
conf.setTitle("Browser market shares in January, 2018");
Tooltip tooltip = new Tooltip();
tooltip.setValueDecimals(1);
conf.setTooltip(tooltip);
PlotOptionsPie plotOptions = new PlotOptionsPie();
plotOptions.setAllowPointSelect(true);
plotOptions.setCursor(Cursor.POINTER);
plotOptions.setShowInLegend(true);
conf.setPlotOptions(plotOptions);
DataSeries series = new DataSeries();
DataSeriesItem chrome = new DataSeriesItem("Chrome", 61.41);
chrome.setSliced(true);
chrome.setSelected(true);
series.add(chrome);
series.add(new DataSeriesItem("Internet Explorer", 11.84));
series.add(new DataSeriesItem("Firefox", 10.85));
series.add(new DataSeriesItem("Edge", 4.67));
series.add(new DataSeriesItem("Safari", 4.18));
series.add(new DataSeriesItem("Sogou Explorer", 1.64));
series.add(new DataSeriesItem("Opera", 6.2));
series.add(new DataSeriesItem("QQ", 1.2));
series.add(new DataSeriesItem("Others", 2.61));
conf.setSeries(series);
chart.setVisibilityTogglingDisabled(true);
listenerRegistration = chart.addPointLegendItemClickListener(event -> {
showNotification("Legend item click" + " : " + event.getItemIndex() + " : " + event.getItem().getName());
});
add(chart);
}
use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class AreaSplineRange method initDemo.
@Override
public void initDemo() {
final Chart chart = new Chart(ChartType.AREASPLINERANGE);
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("Temperature variation by day");
Tooltip tooltip = configuration.getTooltip();
tooltip.setValueSuffix("°C");
DataSeries dataSeries = new DataSeries("Temperatures");
for (StockPrices.RangeData data : StockPrices.fetchDailyTempRanges()) {
dataSeries.add(new DataSeriesItem(data.getDate(), data.getMin(), data.getMax()));
}
configuration.setSeries(dataSeries);
chart.setTimeline(true);
add(chart);
}
Aggregations