Search in sources :

Example 1 with PlotOptionsBar

use of com.vaadin.flow.component.charts.model.PlotOptionsBar 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);
}
Also used : DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) PlotOptionsBar(com.vaadin.flow.component.charts.model.PlotOptionsBar) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Aggregations

Chart (com.vaadin.flow.component.charts.Chart)1 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)1 Configuration (com.vaadin.flow.component.charts.model.Configuration)1 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)1 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)1 PlotOptionsBar (com.vaadin.flow.component.charts.model.PlotOptionsBar)1 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)1 XAxis (com.vaadin.flow.component.charts.model.XAxis)1 YAxis (com.vaadin.flow.component.charts.model.YAxis)1