Search in sources :

Example 16 with ListSeries

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

use of com.vaadin.flow.component.charts.model.ListSeries in project komunumo-server by komunumo.

the class AnalyticsBoard method populateCharts.

private void populateCharts(@NotNull final Year year) {
    // Top row widgets
    final var registrations = databaseService.countAttendeesByYear(year, NoShows.INCLUDE);
    final var events = databaseService.countEventsByYear(year);
    final var noShows = databaseService.countAttendeesByYear(year, NoShows.ONLY);
    numberOfRegistrations.setText(FormatterUtil.formatNumber(registrations));
    numberOfEvents.setText(FormatterUtil.formatNumber(events));
    noShowRate.setText(FormatterUtil.formatNumber(registrations == 0 ? 0 : noShows * 100L / registrations) + "%");
    final var locationColorMap = databaseService.getAllLocationColors();
    // First chart
    final var configuration = monthlyVisitors.getConfiguration();
    databaseService.calculateMonthlyVisitorsByYear(year).stream().map(data -> {
        final var series = new ListSeries(data.location(), data.january(), data.february(), data.march(), data.april(), data.may(), data.june(), data.july(), data.august(), data.september(), data.october(), data.november(), data.december());
        final var colorCode = locationColorMap.get(data.location());
        if (colorCode != null) {
            final var options = new PlotOptionsColumn();
            options.setColor(new SolidColor(colorCode));
            series.setPlotOptions(options);
        }
        return series;
    }).forEach(configuration::addSeries);
    final var x = new XAxis();
    x.setCrosshair(new Crosshair());
    x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    configuration.addxAxis(x);
    final var y = new YAxis();
    y.setMin(0);
    y.setTitle("");
    configuration.addyAxis(y);
    final var tooltip = new Tooltip();
    tooltip.setShared(true);
    configuration.setTooltip(tooltip);
}
Also used : Serial(java.io.Serial) Board(com.vaadin.flow.component.board.Board) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Chart(com.vaadin.flow.component.charts.Chart) Component(com.vaadin.flow.component.Component) CssImport(com.vaadin.flow.component.dependency.CssImport) Crosshair(com.vaadin.flow.component.charts.model.Crosshair) NoShows(org.komunumo.data.entity.NoShows) XAxis(com.vaadin.flow.component.charts.model.XAxis) Div(com.vaadin.flow.component.html.Div) H2(com.vaadin.flow.component.html.H2) DatabaseService(org.komunumo.data.service.DatabaseService) ChartType(com.vaadin.flow.component.charts.model.ChartType) Year(java.time.Year) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis) NotNull(org.jetbrains.annotations.NotNull) Span(com.vaadin.flow.component.html.Span) SolidColor(com.vaadin.flow.component.charts.model.style.SolidColor) FormatterUtil(org.komunumo.util.FormatterUtil) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) Crosshair(com.vaadin.flow.component.charts.model.Crosshair) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) SolidColor(com.vaadin.flow.component.charts.model.style.SolidColor) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 18 with ListSeries

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

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

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

the class DynamicChangingChart method getLineConfiguration.

private Configuration getLineConfiguration() {
    Configuration configuration = new Configuration();
    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));
    return configuration;
}
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) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Aggregations

ListSeries (com.vaadin.flow.component.charts.model.ListSeries)26 Configuration (com.vaadin.flow.component.charts.model.Configuration)24 YAxis (com.vaadin.flow.component.charts.model.YAxis)21 Chart (com.vaadin.flow.component.charts.Chart)17 XAxis (com.vaadin.flow.component.charts.model.XAxis)17 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)11 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)7 Labels (com.vaadin.flow.component.charts.model.Labels)5 Legend (com.vaadin.flow.component.charts.model.Legend)5 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)5 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)4 PlotOptionsArea (com.vaadin.flow.component.charts.model.PlotOptionsArea)4 Test (org.junit.Test)4 Crosshair (com.vaadin.flow.component.charts.model.Crosshair)3 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)3 Pane (com.vaadin.flow.component.charts.model.Pane)3 PlotOptionsLine (com.vaadin.flow.component.charts.model.PlotOptionsLine)3 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)3 NativeButton (com.vaadin.flow.component.html.NativeButton)3 ArrayList (java.util.ArrayList)3