Search in sources :

Example 41 with Configuration

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

the class Area method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.AREA);
    final Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Historic and Estimated Worldwide Population Growth by Region");
    configuration.setSubTitle("Source: Wikipedia.org");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setCategories("1750", "1800", "1850", "1900", "1950", "1999", "2050");
    xAxis.setTickmarkPlacement(TickmarkPlacement.ON);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setTitle("Billions");
    yAxis.getLabels().setFormatter("function () { return this.value / 1000;}");
    configuration.getTooltip().setValueSuffix(" millions");
    PlotOptionsArea plotOptionsArea = new PlotOptionsArea();
    plotOptionsArea.setStacking(Stacking.NORMAL);
    configuration.setPlotOptions(plotOptionsArea);
    configuration.addSeries(new ListSeries("Asia", 502, 635, 809, 947, 1402, 3634, 5268));
    configuration.addSeries(new ListSeries("Africa", 106, 107, 111, 133, 221, 767, 1766));
    configuration.addSeries(new ListSeries("Europe", 163, 203, 276, 408, 547, 729, 628));
    configuration.addSeries(new ListSeries("America", 18, 31, 54, 156, 339, 818, 1201));
    configuration.addSeries(new ListSeries("Oceania", 2, 2, 2, 6, 13, 30, 46));
    add(chart);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsArea(com.vaadin.flow.component.charts.model.PlotOptionsArea) 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 42 with Configuration

use of com.vaadin.flow.component.charts.model.Configuration in project databasemysqlexample by Liskokuningas.

the class DashboardView method afterNavigation.

@Override
public void afterNavigation(AfterNavigationEvent event) {
    // Set some data when this view is displayed.
    // Top row widgets
    usersH2.setText("745");
    eventsH2.setText("54.6k");
    conversionH2.setText("18%");
    // First chart
    Configuration configuration = monthlyVisitors.getConfiguration();
    configuration.addSeries(new ListSeries("Tokyo", 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4));
    configuration.addSeries(new ListSeries("New York", 83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3));
    configuration.addSeries(new ListSeries("London", 48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2));
    configuration.addSeries(new ListSeries("Berlin", 42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1));
    XAxis x = new XAxis();
    x.setCrosshair(new Crosshair());
    x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    configuration.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    configuration.addyAxis(y);
    // Grid
    List<HealthGridItem> gridItems = new ArrayList<>();
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "M\u00FCnster", "Germany", "Good", "badge"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "Cluj-Napoca", "Romania", "Good", "badge"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "Ciudad Victoria", "Mexico", "Good", "badge"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "Ebetsu", "Japan", "Excellent", "badge success"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "S\u00E3o Bernardo do Campo", "Brazil", "Good", "badge"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "Maputo", "Mozambique", "Good", "badge"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "Warsaw", "Poland", "Good", "badge"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "Kasugai", "Japan", "Failing", "badge error"));
    gridItems.add(new HealthGridItem(LocalDate.of(2019, 1, 14), "Lancaster", "United States", "Excellent", "badge success"));
    grid.setItems(gridItems);
    // Second chart
    configuration = responseTimes.getConfiguration();
    configuration.addSeries(new ListSeries("Tokyo", 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(new ListSeries("London", 3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8));
    x = new XAxis();
    x.setCrosshair(new Crosshair());
    x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    configuration.addxAxis(x);
    y = new YAxis();
    y.setMin(0);
    configuration.addyAxis(y);
}
Also used : Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Crosshair(com.vaadin.flow.component.charts.model.Crosshair) ArrayList(java.util.ArrayList) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 43 with Configuration

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

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

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

Aggregations

Configuration (com.vaadin.flow.component.charts.model.Configuration)72 Chart (com.vaadin.flow.component.charts.Chart)48 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)32 YAxis (com.vaadin.flow.component.charts.model.YAxis)32 XAxis (com.vaadin.flow.component.charts.model.XAxis)25 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)24 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)20 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)19 Test (org.junit.Test)16 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)12 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)10 Path (java.nio.file.Path)10 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)9 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)8 Legend (com.vaadin.flow.component.charts.model.Legend)8 Labels (com.vaadin.flow.component.charts.model.Labels)7 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)6 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)5 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)5 Pane (com.vaadin.flow.component.charts.model.Pane)4