Search in sources :

Example 31 with Chart

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

the class ColumnLineAndPie method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Combined Chart");
    conf.setExporting(true);
    XAxis x = new XAxis();
    x.setCategories(new String[] { "Apples", "Oranges", "Pears", "Bananas", "Plums" });
    conf.addxAxis(x);
    Style labelStyle = new Style();
    labelStyle.setTop("8px");
    labelStyle.setLeft("40px");
    conf.setLabels(new HTMLLabels(labelStyle, new HTMLLabelItem("Total fruit consumption")));
    DataSeries series = new DataSeries();
    PlotOptionsColumn plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("Jane");
    series.setData(3, 2, 1, 3, 4);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("John");
    series.setData(2, 3, 5, 7, 6);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptions = new PlotOptionsColumn();
    series.setPlotOptions(plotOptions);
    series.setName("Joe");
    series.setData(4, 3, 3, 9, 0);
    conf.addSeries(series);
    series = new DataSeries();
    PlotOptionsSpline splinePlotOptions = new PlotOptionsSpline();
    series.setPlotOptions(splinePlotOptions);
    series.setName("Average");
    series.setData(3, 2.67, 3, 6.33, 3.33);
    conf.addSeries(series);
    series = new DataSeries();
    series.setPlotOptions(new PlotOptionsPie());
    series.setName("Total consumption");
    DataSeriesItem item = new DataSeriesItem("Jane", 13);
    series.add(item);
    item = new DataSeriesItem("John", 23);
    series.add(item);
    item = new DataSeriesItem("Joe", 19);
    series.add(item);
    PlotOptionsPie plotOptionsPie = new PlotOptionsPie();
    plotOptionsPie.setSize("100px");
    plotOptionsPie.setCenter("100px", "80px");
    plotOptionsPie.setShowInLegend(false);
    series.setPlotOptions(plotOptionsPie);
    conf.addSeries(series);
    add(chart);
}
Also used : HTMLLabelItem(com.vaadin.flow.component.charts.model.HTMLLabelItem) PlotOptionsPie(com.vaadin.flow.component.charts.model.PlotOptionsPie) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) Style(com.vaadin.flow.component.charts.model.style.Style) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) PlotOptionsSpline(com.vaadin.flow.component.charts.model.PlotOptionsSpline) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) HTMLLabels(com.vaadin.flow.component.charts.model.HTMLLabels)

Example 32 with Chart

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

the class ScatterAndPolygon method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.SCATTER);
    Configuration conf = chart.getConfiguration();
    chart.setId("chart");
    conf.getChart().setZoomType(Dimension.XY);
    conf.disableCredits();
    conf.setTitle("Height vs Weight");
    conf.setSubTitle("Polygon series in Vaadin Charts.");
    Tooltip tooltip = conf.getTooltip();
    tooltip.setHeaderFormat("<b>{series.name}</b><br>");
    tooltip.setPointFormat("{point.x} cm, {point.y} kg");
    XAxis xAxis = conf.getxAxis();
    xAxis.setStartOnTick(true);
    xAxis.setEndOnTick(true);
    xAxis.setShowLastLabel(true);
    xAxis.setTitle("Height (cm)");
    YAxis yAxis = conf.getyAxis();
    yAxis.setTitle("Weight (kg)");
    PlotOptionsScatter plotOptionsScatter = new PlotOptionsScatter();
    DataSeries scatter = new DataSeries();
    scatter.setPlotOptions(plotOptionsScatter);
    scatter.setName("Observations");
    fillScatter(scatter);
    DataSeries polygon = new DataSeries();
    PlotOptionsPolygon plotOptionsPolygon = new PlotOptionsPolygon();
    plotOptionsPolygon.setEnableMouseTracking(false);
    polygon.setPlotOptions(plotOptionsPolygon);
    polygon.setName("Target");
    polygon.add(new DataSeriesItem(153, 42));
    polygon.add(new DataSeriesItem(149, 46));
    polygon.add(new DataSeriesItem(149, 55));
    polygon.add(new DataSeriesItem(152, 60));
    polygon.add(new DataSeriesItem(159, 70));
    polygon.add(new DataSeriesItem(170, 77));
    polygon.add(new DataSeriesItem(180, 70));
    polygon.add(new DataSeriesItem(180, 60));
    polygon.add(new DataSeriesItem(173, 52));
    polygon.add(new DataSeriesItem(166, 45));
    conf.addSeries(polygon);
    conf.addSeries(scatter);
    add(chart);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsScatter(com.vaadin.flow.component.charts.model.PlotOptionsScatter) PlotOptionsPolygon(com.vaadin.flow.component.charts.model.PlotOptionsPolygon) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) 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) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 33 with Chart

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

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

the class DynamicExtremes method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setType(ChartType.LINE);
    configuration.getChart().setMarginRight(130);
    configuration.getChart().setMarginBottom(25);
    configuration.getTitle().setText("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.setMin(-10d);
    yAxis.setMax(30d);
    yAxis.setTitle(new AxisTitle("Temperature (°C)"));
    yAxis.getTitle().setAlign(VerticalAlign.HIGH);
    configuration.getTooltip().setFormatter("return '<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
    PlotOptionsLine plotOptions = new PlotOptionsLine();
    plotOptions.setDataLabels(new DataLabels(true));
    configuration.setPlotOptions(plotOptions);
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(-10d);
    legend.setY(100d);
    ListSeries ls = new ListSeries();
    ls.setName("Tokyo");
    ls.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);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("New York");
    ls.setData(-0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("Berlin");
    ls.setData(-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0);
    configuration.addSeries(ls);
    ls = new ListSeries();
    ls.setName("London");
    ls.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);
    configuration.addSeries(ls);
    NativeButton toggleExtremesButton = new NativeButton("Toggle extremes", e -> {
        if (setExtremes) {
            chart.getConfiguration().getyAxes().getAxis(0).setExtremes(10, 15);
        } else {
            chart.getConfiguration().resetZoom();
        }
        setExtremes = !setExtremes;
    });
    toggleExtremesButton.setId("toggleExtremesButton");
    add(chart, toggleExtremesButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Legend(com.vaadin.flow.component.charts.model.Legend) DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsLine(com.vaadin.flow.component.charts.model.PlotOptionsLine) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) Chart(com.vaadin.flow.component.charts.Chart) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 35 with Chart

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

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