Search in sources :

Example 16 with DataSeriesItem

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

the class DynamicChanges method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.PIE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Browser market shares at a specific website, 2010");
    DataSeries series = new DataSeries(getInitialData());
    conf.setSeries(series);
    Input addPointButton = new Input();
    addPointButton.setValue("Add Point");
    addPointButton.setType("button");
    addPointButton.setId("addPointButton");
    ComponentUtil.addListener(addPointButton, ClickEvent.class, (ComponentEventListener) e -> {
        String randomName = "Random browser " + Math.floor(Math.random() * 20);
        double randomValue = Math.random() * 20;
        series.add(new DataSeriesItem(randomName, randomValue));
    });
    Input removePointButton = new Input();
    removePointButton.setValue("Remove Point");
    removePointButton.setId("removePointButton");
    removePointButton.setType("button");
    ComponentUtil.addListener(removePointButton, ClickEvent.class, (ComponentEventListener) e -> {
        if (!series.getData().isEmpty()) {
            series.remove(series.getData().get(0));
        }
    });
    Input updatePointButton = new Input();
    updatePointButton.setValue("Update Point");
    updatePointButton.setId("updatePointButton");
    updatePointButton.setType("button");
    ComponentUtil.addListener(updatePointButton, ClickEvent.class, (ComponentEventListener) e -> {
        if (!series.getData().isEmpty()) {
            DataSeriesItem item = series.getData().get(0);
            item.setY(Math.random() * 20);
            series.update(item);
        }
    });
    Input slicePointButton = new Input();
    slicePointButton.setValue("Slice Point");
    slicePointButton.setId("slicePointButton");
    slicePointButton.setType("button");
    ComponentUtil.addListener(slicePointButton, ClickEvent.class, (ComponentEventListener) e -> {
        if (!series.getData().isEmpty()) {
            DataSeriesItem item = series.getData().get(0);
            item.setX(Math.random() * 20);
            series.setItemSliced(0, !item.getSliced());
        }
    });
    Input disableSeriesButton = new Input();
    disableSeriesButton.setValue("Toggle Series Visibility");
    disableSeriesButton.setId("disableSeriesButton");
    disableSeriesButton.setType("button");
    ComponentUtil.addListener(disableSeriesButton, ClickEvent.class, (ComponentEventListener) e -> {
        series.setVisible(!series.isVisible());
    });
    Input resetSeriesButton = new Input();
    resetSeriesButton.setValue("Reset Series");
    resetSeriesButton.setId("resetSeriesButton");
    resetSeriesButton.setType("button");
    ComponentUtil.addListener(resetSeriesButton, ClickEvent.class, (ComponentEventListener) e -> {
        series.setData(getInitialData());
        series.updateSeries();
    });
    add(chart, addPointButton, removePointButton, updatePointButton, slicePointButton, disableSeriesButton, resetSeriesButton);
}
Also used : ComponentEventListener(com.vaadin.flow.component.ComponentEventListener) Chart(com.vaadin.flow.component.charts.Chart) SkipFromDemo(com.vaadin.flow.component.charts.examples.SkipFromDemo) ComponentUtil(com.vaadin.flow.component.ComponentUtil) ClickEvent(com.vaadin.flow.component.ClickEvent) AbstractChartExample(com.vaadin.flow.component.charts.examples.AbstractChartExample) Configuration(com.vaadin.flow.component.charts.model.Configuration) ArrayList(java.util.ArrayList) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) List(java.util.List) ChartType(com.vaadin.flow.component.charts.model.ChartType) Input(com.vaadin.flow.component.html.Input) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Input(com.vaadin.flow.component.html.Input) Configuration(com.vaadin.flow.component.charts.model.Configuration) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 17 with DataSeriesItem

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

the class ServerSideEvents method initDemo.

@Override
public void initDemo() {
    historyLayout = new OrderedList();
    historyLayout.setId("history");
    chart = new Chart();
    chart.setId("chart");
    final Configuration configuration = chart.getConfiguration();
    configuration.getChart().setWidth(500);
    configuration.getChart().setType(ChartType.SCATTER);
    configuration.getTitle().setText("Test server side events.");
    configuration.getSubTitle().setText("When an event occurs, the details are shown below the chart");
    configuration.setExporting(true);
    configuration.getChart().setAnimation(false);
    configuration.getChart().setZoomType(Dimension.XY);
    configuration.getAccessibility().setEnabled(false);
    XAxis xAxis = configuration.getxAxis();
    xAxis.setMinPadding(0.2);
    xAxis.setMaxPadding(0.2);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle(new AxisTitle("Value"));
    PlotLine plotline = new PlotLine();
    plotline.setValue(0);
    plotline.setWidth(1);
    plotline.setColor(new SolidColor("#808080"));
    yAxis.setPlotLines(plotline);
    yAxis.setMinPadding(0.2);
    yAxis.setMaxPadding(0.2);
    YAxis yAxis1 = new YAxis();
    yAxis1.setTitle("Another axis");
    yAxis1.setOpposite(true);
    configuration.addyAxis(yAxis1);
    PlotOptionsSeries opt = new PlotOptionsSeries();
    opt.setShowCheckbox(true);
    opt.setAllowPointSelect(true);
    configuration.setPlotOptions(opt);
    configuration.setTooltip(new Tooltip(false));
    final DataSeries series1 = createDataSeries(0);
    final DataSeries series2 = createDataSeries(20);
    DataSeries series3 = createDataSeries(100);
    series3.get(0).setY(105);
    series3.get(3).setY(95);
    series3.setName("Another axis");
    series3.setyAxis(1);
    DataSeriesItem firstDataPoint = series1.get(0);
    firstDataPoint.setSelected(true);
    configuration.setSeries(series1, series2, series3);
    chart.addChartClickListener(this::logEvent);
    chart.addPointClickListener(this::logEvent);
    chart.addCheckBoxClickListener(this::logEvent);
    chart.addSeriesLegendItemClickListener(this::logEvent);
    chart.addSeriesHideListener(this::logEvent);
    chart.addSeriesShowListener(this::logEvent);
    chart.addPointSelectListener(this::logEvent);
    chart.addPointUnselectListener(this::logEvent);
    chart.addYAxesExtremesSetListener(this::logEvent);
    chart.drawChart();
    chart.setVisibilityTogglingDisabled(false);
    VerticalLayout layout = new VerticalLayout();
    layout.setId("master");
    layout.add(createControls());
    layout.add(new H2("Event History"), historyLayout);
    add(chart, layout);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) SolidColor(com.vaadin.flow.component.charts.model.style.SolidColor) H2(com.vaadin.flow.component.html.H2) XAxis(com.vaadin.flow.component.charts.model.XAxis) OrderedList(com.vaadin.flow.component.html.OrderedList) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) PlotLine(com.vaadin.flow.component.charts.model.PlotLine) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) Chart(com.vaadin.flow.component.charts.Chart) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 18 with DataSeriesItem

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

the class ServerSideEvents method createDataSeries.

private DataSeries createDataSeries(Number yvalue) {
    final DataSeries series = new DataSeries();
    series.add(new DataSeriesItem(20, yvalue));
    series.add(new DataSeriesItem(40, yvalue.intValue() + 10));
    series.add(new DataSeriesItem(60, yvalue.intValue() - 15));
    series.add(new DataSeriesItem(80, yvalue));
    series.setId("" + id);
    series.setName("Test Series " + id++);
    return series;
}
Also used : DataSeries(com.vaadin.flow.component.charts.model.DataSeries) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 19 with DataSeriesItem

use of com.vaadin.flow.component.charts.model.DataSeriesItem 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 20 with DataSeriesItem

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

Aggregations

DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)29 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)26 Chart (com.vaadin.flow.component.charts.Chart)20 Configuration (com.vaadin.flow.component.charts.model.Configuration)20 XAxis (com.vaadin.flow.component.charts.model.XAxis)10 YAxis (com.vaadin.flow.component.charts.model.YAxis)10 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)9 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)6 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)5 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)4 AbstractChartExample (com.vaadin.flow.component.charts.examples.AbstractChartExample)3 ChartType (com.vaadin.flow.component.charts.model.ChartType)3 DataLabelsFunnel (com.vaadin.flow.component.charts.model.DataLabelsFunnel)3 PlotLine (com.vaadin.flow.component.charts.model.PlotLine)3 PlotOptionsPie (com.vaadin.flow.component.charts.model.PlotOptionsPie)3 PlotOptionsScatter (com.vaadin.flow.component.charts.model.PlotOptionsScatter)3 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)3 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)2 Cursor (com.vaadin.flow.component.charts.model.Cursor)2 Legend (com.vaadin.flow.component.charts.model.Legend)2