Search in sources :

Example 6 with AxisTitle

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

Example 7 with AxisTitle

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

the class SplineUpdatingEachSecond method initDemo.

@Override
public void initDemo() {
    // NOSONAR
    final Random random = new Random();
    final Chart chart = new Chart();
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.SPLINE);
    configuration.getTitle().setText("Live random data");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setType(AxisType.DATETIME);
    xAxis.setTickPixelInterval(150);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    configuration.getTooltip().setEnabled(false);
    configuration.getLegend().setEnabled(false);
    final DataSeries series = new DataSeries();
    series.setPlotOptions(new PlotOptionsSpline());
    series.setName("Random data");
    for (int i = -19; i <= 0; i++) {
        series.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
    }
    configuration.setSeries(series);
    runWhileAttached(chart, () -> {
        final long x = System.currentTimeMillis();
        final double y = random.nextDouble();
        series.add(new DataSeriesItem(x, y), true, true);
    }, 1000, 1000);
    add(chart);
}
Also used : Random(java.util.Random) Configuration(com.vaadin.flow.component.charts.model.Configuration) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) PlotOptionsSpline(com.vaadin.flow.component.charts.model.PlotOptionsSpline) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 8 with AxisTitle

use of com.vaadin.flow.component.charts.model.AxisTitle 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)8 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Configuration (com.vaadin.flow.component.charts.model.Configuration)8 YAxis (com.vaadin.flow.component.charts.model.YAxis)8 XAxis (com.vaadin.flow.component.charts.model.XAxis)6 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)5 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)4 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)4 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)3 Legend (com.vaadin.flow.component.charts.model.Legend)3 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)2 PlotOptionsLine (com.vaadin.flow.component.charts.model.PlotOptionsLine)2 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)2 PlotOptionsSpline (com.vaadin.flow.component.charts.model.PlotOptionsSpline)2 Labels (com.vaadin.flow.component.charts.model.Labels)1 PlotBand (com.vaadin.flow.component.charts.model.PlotBand)1 PlotLine (com.vaadin.flow.component.charts.model.PlotLine)1 PlotOptionsArea (com.vaadin.flow.component.charts.model.PlotOptionsArea)1 PlotOptionsBar (com.vaadin.flow.component.charts.model.PlotOptionsBar)1 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)1