Search in sources :

Example 26 with Chart

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

the class ColumnWithNegativeValues method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Column chart with negative values"));
    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setMinPointLength(3);
    conf.setPlotOptions(column);
    XAxis xAxis = new XAxis();
    xAxis.setCategories("Apples", "Oranges", "Pears", "Grapes", "Bananas");
    conf.addxAxis(xAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("function() { return ''+ this.series.name +': '+ this.y +'';}");
    conf.setTooltip(tooltip);
    conf.setCredits(new Credits(false));
    conf.addSeries(new ListSeries("John", 5, 0.1, 4, 7, 2));
    conf.addSeries(new ListSeries("Jane", 2, -2, -0.1, 2, 1));
    conf.addSeries(new ListSeries("Joe", 3, 4, 4, -2, 5));
    add(chart);
}
Also used : Credits(com.vaadin.flow.component.charts.model.Credits) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Title(com.vaadin.flow.component.charts.model.Title) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis)

Example 27 with Chart

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

the class MultipleAxes method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.getChart().setZoomType(Dimension.XY);
    conf.setTitle("Average Monthly Weather Data for Tokyo");
    conf.setSubTitle("Source: WorldClimate.com");
    XAxis x = new XAxis();
    x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    conf.addxAxis(x);
    YAxis y1 = new YAxis();
    y1.setShowEmpty(false);
    y1.setTitle(new AxisTitle("Temperature"));
    Labels labels = new Labels();
    labels.setFormatter("return this.value +'°C'");
    y1.setLabels(labels);
    y1.setOpposite(true);
    y1.setClassName("y1");
    conf.addyAxis(y1);
    YAxis y2 = new YAxis();
    y2.setShowEmpty(false);
    y2.setTitle(new AxisTitle("Rainfall"));
    labels = new Labels();
    labels.setFormatter("return this.value +' mm'");
    y2.setLabels(labels);
    y2.setClassName("y2");
    conf.addyAxis(y2);
    YAxis y3 = new YAxis();
    y3.setShowEmpty(false);
    y3.setTitle(new AxisTitle("Sea-Level Pressure"));
    labels = new Labels();
    labels.setFormatter("return this.value +' mb'");
    y3.setLabels(labels);
    y3.setOpposite(true);
    y3.setClassName("y3");
    conf.addyAxis(y3);
    Tooltip tooltip = new Tooltip();
    tooltip.setFormatter("function() { " + "var unit = { 'Rainfall': 'mm', 'Temperature': '°C', 'Sea-Level Pressure': 'mb' }[this.series.name];" + "return ''+ this.x +': '+ this.y +' '+ unit; }");
    conf.setTooltip(tooltip);
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setX(120);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setY(80);
    legend.setFloating(true);
    conf.setLegend(legend);
    DataSeries series = new DataSeries();
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    series.setPlotOptions(plotOptionsColumn);
    series.setName("Rainfall");
    series.setyAxis(1);
    series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    conf.addSeries(series);
    series = new DataSeries();
    PlotOptionsSpline plotOptionsSpline = new PlotOptionsSpline();
    series.setPlotOptions(plotOptionsSpline);
    series.setName("Sea-Level Pressure");
    series.setyAxis(2);
    series.setData(1016, 1016, 1015.9, 1015.5, 1012.3, 1009.5, 1009.6, 1010.2, 1013.1, 1016.9, 1018.2, 1016.7);
    conf.addSeries(series);
    series = new DataSeries();
    plotOptionsSpline = new PlotOptionsSpline();
    series.setPlotOptions(plotOptionsSpline);
    series.setName("Temperature");
    series.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);
    conf.addSeries(series);
    add(chart);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Labels(com.vaadin.flow.component.charts.model.Labels) 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) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 28 with Chart

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

use of com.vaadin.flow.component.charts.Chart in project DoodleVerse by davidemarcoli.

the class StatisticsView method setupPage.

public void setupPage() {
    Chart moneyBoxplot = new Chart(ChartType.BOXPLOT);
    // Modify the default configuration a bit
    Configuration conf = moneyBoxplot.getConfiguration();
    conf.setTitle("Money Boxplot");
    conf.getLegend().setEnabled(false);
    // Set median line color and thickness
    PlotOptionsBoxplot plotOptions = new PlotOptionsBoxplot();
    plotOptions.setWhiskerLength("80%");
    plotOptions.setAllowPointSelect(true);
    conf.setPlotOptions(plotOptions);
    DataSeries series = new DataSeries();
    PersonStatAnalysis analysis = new PersonStatAnalysis(personRepository.findAll());
    series.add(new BoxPlotItem(analysis.low(), analysis.quartile(25), analysis.median(), analysis.quartile(75), analysis.high()));
    conf.setSeries(series);
    add(moneyBoxplot);
    setSizeFull();
}
Also used : Chart(com.vaadin.flow.component.charts.Chart)

Example 30 with Chart

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

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