Search in sources :

Example 36 with Chart

use of com.vaadin.flow.component.charts.Chart 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 37 with Chart

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

the class Line method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Solar Employment Growth by Sector, 2010-2016");
    configuration.setSubTitle("Source: thesolarfoundation.com");
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle("Number of Employees");
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setVerticalAlign(VerticalAlign.MIDDLE);
    legend.setAlign(HorizontalAlign.RIGHT);
    PlotOptionsSeries plotOptionsSeries = new PlotOptionsSeries();
    plotOptionsSeries.setPointStart(2010);
    configuration.setPlotOptions(plotOptionsSeries);
    configuration.addSeries(new ListSeries("Installation", 43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175));
    configuration.addSeries(new ListSeries("Manufacturing", 24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434));
    configuration.addSeries(new ListSeries("Sales & Distribution", 11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387));
    configuration.addSeries(new ListSeries("Project Development", null, null, 7988, 12169, 15112, 22452, 34400, 34227));
    configuration.addSeries(new ListSeries("Other", 12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111));
    add(chart);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Chart(com.vaadin.flow.component.charts.Chart) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 38 with Chart

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

the class Scatter method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.SCATTER);
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Height Versus Weight of 507 Individuals by Gender");
    configuration.setSubTitle("Source: Heinz  2003");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setTitle("Height (cm)");
    xAxis.setStartOnTick(true);
    xAxis.setEndOnTick(true);
    xAxis.setShowLastLabel(true);
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(100);
    legend.setY(70);
    legend.setFloating(true);
    PlotOptionsScatter plotOptionsScatter = new PlotOptionsScatter();
    SeriesTooltip scatterTooltip = plotOptionsScatter.getTooltip();
    scatterTooltip.setHeaderFormat("<b>{series.name}</b><br>\",\"pointFormat\":\"{point.x} cm, {point.y} kg");
    DataSeries femaleSeries = new DataSeries();
    femaleSeries.setName("Female");
    PlotOptionsScatter femalePlotOptions = new PlotOptionsScatter();
    femalePlotOptions.setClassName("femaleSeries");
    femaleSeries.setPlotOptions(femalePlotOptions);
    Number[][] femaleData = getFemaleData();
    for (int i = 0; i < femaleData.length; i++) {
        DataSeriesItem item = new DataSeriesItem(femaleData[i][1], femaleData[i][0]);
        femaleSeries.add(item);
    }
    configuration.addSeries(femaleSeries);
    DataSeries maleSeries = new DataSeries();
    maleSeries.setName("Male");
    PlotOptionsScatter malePlotOptions = new PlotOptionsScatter();
    malePlotOptions.setClassName("maleSeries");
    maleSeries.setPlotOptions(malePlotOptions);
    Number[][] maleData = getMaleData();
    for (int i = 0; i < maleData.length; i++) {
        DataSeriesItem item = new DataSeriesItem(maleData[i][1], maleData[i][0]);
        maleSeries.add(item);
    }
    configuration.addSeries(maleSeries);
    add(chart);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsScatter(com.vaadin.flow.component.charts.model.PlotOptionsScatter) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip)

Example 39 with Chart

use of com.vaadin.flow.component.charts.Chart 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 40 with Chart

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

the class BoxPlot method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart();
    chart.getConfiguration().setTitle("Box Plot Example");
    Legend legend = new Legend();
    legend.setEnabled(false);
    chart.getConfiguration().setLegend(legend);
    XAxis xaxis = chart.getConfiguration().getxAxis();
    xaxis.setTitle("Experiment No.");
    xaxis.setCategories("1", "2", "3", "4", "5");
    YAxis yAxis = chart.getConfiguration().getyAxis();
    yAxis.setTitle("Observations");
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(932);
    plotLine.setZIndex(0);
    Label label = new Label("Theoretical mean: 932");
    label.setAlign(HorizontalAlign.CENTER);
    plotLine.setLabel(label);
    yAxis.setPlotLines(plotLine);
    final DataSeries observations = new DataSeries();
    observations.setName("Observations");
    // Add PlotBoxItems contain all fields relevant for plot box chart
    observations.add(new BoxPlotItem(760, 801, 848, 895, 965));
    // Example with no arg constructor
    BoxPlotItem plotBoxItem = new BoxPlotItem();
    plotBoxItem.setLow(733);
    plotBoxItem.setLowerQuartile(853);
    plotBoxItem.setMedian(939);
    plotBoxItem.setUpperQuartile(980);
    plotBoxItem.setHigh(1080);
    observations.add(plotBoxItem);
    observations.add(new BoxPlotItem(714, 762, 817, 870, 918));
    observations.add(new BoxPlotItem(724, 802, 806, 871, 950));
    observations.add(new BoxPlotItem(834, 836, 864, 882, 910));
    PlotOptionsBoxplot plotOptions = new PlotOptionsBoxplot();
    SeriesTooltip observationsTooltip = new SeriesTooltip();
    observationsTooltip.setHeaderFormat("<em>Experiment No {point.key}</em><br/>");
    plotOptions.setTooltip(observationsTooltip);
    observations.setPlotOptions(plotOptions);
    chart.getConfiguration().addSeries(observations);
    final DataSeries outlier = new DataSeries();
    outlier.setName("Outlier");
    outlier.add(new DataSeriesItem(0, 644));
    outlier.add(new DataSeriesItem(4, 718));
    outlier.add(new DataSeriesItem(4, 951));
    outlier.add(new DataSeriesItem(4, 969));
    PlotOptionsScatter outlierOptions = new PlotOptionsScatter();
    SeriesTooltip outlierTooltip = new SeriesTooltip();
    outlierTooltip.setPointFormat("Observation: {point.y}");
    outlierOptions.setTooltip(outlierTooltip);
    outlier.setPlotOptions(outlierOptions);
    chart.getConfiguration().addSeries(outlier);
    Checkbox useCustomStyles = new Checkbox("Use custom styling");
    useCustomStyles.addValueChangeListener(e -> {
        PlotOptionsBoxplot options = new PlotOptionsBoxplot();
        if (e.getValue()) {
            options.setClassName("custom-style");
            options.setWhiskerLength("70");
        }
        observations.setPlotOptions(options);
        chart.drawChart(true);
    });
    add(chart, useCustomStyles);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) PlotOptionsScatter(com.vaadin.flow.component.charts.model.PlotOptionsScatter) Label(com.vaadin.flow.component.charts.model.Label) XAxis(com.vaadin.flow.component.charts.model.XAxis) BoxPlotItem(com.vaadin.flow.component.charts.model.BoxPlotItem) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) PlotOptionsBoxplot(com.vaadin.flow.component.charts.model.PlotOptionsBoxplot) PlotLine(com.vaadin.flow.component.charts.model.PlotLine) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) YAxis(com.vaadin.flow.component.charts.model.YAxis) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip)

Aggregations

Chart (com.vaadin.flow.component.charts.Chart)57 Configuration (com.vaadin.flow.component.charts.model.Configuration)48 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)32 YAxis (com.vaadin.flow.component.charts.model.YAxis)31 XAxis (com.vaadin.flow.component.charts.model.XAxis)26 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)20 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)20 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)17 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)15 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)13 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Legend (com.vaadin.flow.component.charts.model.Legend)8 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)6 Labels (com.vaadin.flow.component.charts.model.Labels)6 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)6 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)6 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)5 ChartType (com.vaadin.flow.component.charts.model.ChartType)4 SolidColor (com.vaadin.flow.component.charts.model.style.SolidColor)4 AbstractChartExample (com.vaadin.flow.component.charts.examples.AbstractChartExample)3