use of com.vaadin.flow.component.charts.model.Configuration 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.Configuration in project flow-components by vaadin.
the class HeatMap method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart();
Configuration config = chart.getConfiguration();
config.getChart().setType(ChartType.HEATMAP);
config.getChart().setMarginTop(40);
config.getChart().setMarginBottom(40);
config.getTitle().setText("Sales per employee per weekday");
config.getxAxis().setCategories("Marta", "Mysia", "Misiek", "Maniek", "Miki", "Guillermo", "Jonatan", "Zdzisław", "Antoni", "Zygmunt");
config.getyAxis().setCategories("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");
config.getColorAxis().setMin(0);
config.getColorAxis().setMinColor(SolidColor.WHITE);
SolidColor lightBlue = new SolidColor(22, 118, 243);
config.getColorAxis().setMaxColor(lightBlue);
config.getLegend().setLayout(LayoutDirection.VERTICAL);
config.getLegend().setAlign(HorizontalAlign.RIGHT);
config.getLegend().setMargin(0);
config.getLegend().setVerticalAlign(VerticalAlign.TOP);
config.getLegend().setY(25);
config.getLegend().setSymbolHeight(320);
HeatSeries rs = new HeatSeries("Sales per employee", getRawData());
PlotOptionsHeatmap plotOptionsHeatmap = new PlotOptionsHeatmap();
plotOptionsHeatmap.setDataLabels(new DataLabels());
plotOptionsHeatmap.getDataLabels().setEnabled(true);
SeriesTooltip tooltip = new SeriesTooltip();
tooltip.setHeaderFormat("{series.name}<br/>");
tooltip.setPointFormat("Amount: <b>{point.value}</b> ");
plotOptionsHeatmap.setTooltip(tooltip);
config.setPlotOptions(plotOptionsHeatmap);
config.setSeries(rs);
add(chart);
}
use of com.vaadin.flow.component.charts.model.Configuration 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.Configuration 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.Configuration in project flow-components by vaadin.
the class ColumnWithLazyMultiLevelDrilldownCallbackTests method initDemo.
@Override
public void initDemo() {
log = new OrderedList();
log.setId("log");
Div layout = new Div();
final Chart chart = new Chart(ChartType.COLUMN);
chart.setId("chart");
final Configuration conf = chart.getConfiguration();
PlotOptionsColumn column = new PlotOptionsColumn();
column.setCursor(Cursor.POINTER);
column.setAnimation(false);
conf.getDrilldown().setAnimation(false);
column.setDataLabels(new DataLabels(true));
conf.setPlotOptions(column);
DataSeries series = new DataSeries();
series.setName("Top");
createItems("Item").forEach(series::addItemWithDrilldown);
conf.addSeries(series);
chart.addChartDrillupListener(event -> log("ChartDrillupEvent"));
final NativeButton setNew = new NativeButton("set new callback", e -> chart.setDrilldownCallback(getDrilldownCallback()));
setNew.setId("setNew");
final NativeButton setSame = new NativeButton("set same callback", e -> chart.setDrilldownCallback(chart.getDrilldownCallback()));
setSame.setId("setSame");
final NativeButton setNull = new NativeButton("set null callback", e -> chart.setDrilldownCallback(null));
setNull.setId("setNull");
layout.add(chart, setNew, setSame, setNull, log);
add(layout);
}
Aggregations