Search in sources :

Example 21 with ListSeries

use of com.vaadin.flow.component.charts.model.ListSeries 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);
}
Also used : PlotOptionsGauge(com.vaadin.flow.component.charts.model.PlotOptionsGauge) DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Random(java.util.Random) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Labels(com.vaadin.flow.component.charts.model.Labels) DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Chart(com.vaadin.flow.component.charts.Chart) YAxis(com.vaadin.flow.component.charts.model.YAxis) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip)

Example 22 with ListSeries

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

Example 23 with ListSeries

use of com.vaadin.flow.component.charts.model.ListSeries 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)

Example 24 with ListSeries

use of com.vaadin.flow.component.charts.model.ListSeries in project flow-components by vaadin.

the class SVGGeneratorTest method createAreaChartConfiguration.

private Configuration createAreaChartConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setTitle("First Chart for Flow");
    configuration.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);
    return configuration;
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 25 with ListSeries

use of com.vaadin.flow.component.charts.model.ListSeries in project flow-components by vaadin.

the class ConfigurationTest method configurationSetSeriesWithArraysAsListTest.

@Test(expected = Test.None.class)
public void configurationSetSeriesWithArraysAsListTest() {
    Configuration conf = new Configuration();
    conf.setSeries(Arrays.asList(new ListSeries()));
    conf.addSeries(new ListSeries());
    assertEquals(conf.getSeries().size(), 2);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Test(org.junit.Test)

Aggregations

ListSeries (com.vaadin.flow.component.charts.model.ListSeries)26 Configuration (com.vaadin.flow.component.charts.model.Configuration)24 YAxis (com.vaadin.flow.component.charts.model.YAxis)21 Chart (com.vaadin.flow.component.charts.Chart)17 XAxis (com.vaadin.flow.component.charts.model.XAxis)17 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)11 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)7 Labels (com.vaadin.flow.component.charts.model.Labels)5 Legend (com.vaadin.flow.component.charts.model.Legend)5 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)5 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)4 PlotOptionsArea (com.vaadin.flow.component.charts.model.PlotOptionsArea)4 Test (org.junit.Test)4 Crosshair (com.vaadin.flow.component.charts.model.Crosshair)3 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)3 Pane (com.vaadin.flow.component.charts.model.Pane)3 PlotOptionsLine (com.vaadin.flow.component.charts.model.PlotOptionsLine)3 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)3 NativeButton (com.vaadin.flow.component.html.NativeButton)3 ArrayList (java.util.ArrayList)3