Search in sources :

Example 16 with YAxis

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

the class ColumnWithNativeLazyDrilldownByIndex method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.COLUMN);
    chart.setId("chart");
    conf = chart.getConfiguration();
    conf.setTitle("Browser market share, April, 2011");
    conf.setSubTitle("Click the columns to view versions. Click again to view brands.");
    conf.getLegend().setEnabled(false);
    XAxis x = new XAxis();
    x.setType(AxisType.CATEGORY);
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setTitle("Total percent market share");
    conf.addyAxis(y);
    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setCursor(Cursor.POINTER);
    column.setDataLabels(new DataLabels(true));
    conf.setPlotOptions(column);
    Tooltip tooltip = new Tooltip();
    tooltip.setEnabled(false);
    conf.setTooltip(tooltip);
    topCategories = new String[] { "MSIE", "Firefox", "Chrome", "Safari", "Opera" };
    DataSeries series = new DataSeries();
    series.setName("Browser brands");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setColorByPoint(true);
    series.setPlotOptions(plotOptionsColumn);
    DataSeriesItem item = new DataSeriesItem("MSIE", 55.11);
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Firefox", 21.63);
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Chrome", 11.94);
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Safari", 7.15);
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Opera", 2.14);
    series.addItemWithDrilldown(item);
    conf.addSeries(series);
    drillSeries = new HashMap<String, DataSeries>();
    DataSeries drill = new DataSeries("MSIE versions");
    String[] categories = new String[] { "MSIE 6.0", "MSIE 7.0", "MSIE 8.0", "MSIE 9.0" };
    Number[] ys = new Number[] { 10.85, 7.35, 33.06, 2.81 };
    drill.setData(categories, ys);
    drill.setId("MSIE");
    drillSeries.put("MSIE", drill);
    drill = new DataSeries("Firefox versions");
    categories = new String[] { "Firefox 2.0", "Firefox 3.0", "Firefox 3.5", "Firefox 3.6", "Firefox 4.0" };
    ys = new Number[] { 0.20, 0.83, 1.58, 13.12, 5.43 };
    drill.setData(categories, ys);
    drill.setId("Firefox");
    drillSeries.put("Firefox", drill);
    drill = new DataSeries("Chrome versions");
    categories = new String[] { "Chrome 5.0", "Chrome 6.0", "Chrome 7.0", "Chrome 8.0", "Chrome 9.0", "Chrome 10.0", "Chrome 11.0", "Chrome 12.0" };
    ys = new Number[] { 0.12, 0.19, 0.12, 0.36, 0.32, 9.91, 0.50, 0.22 };
    drill.setData(categories, ys);
    drill.setId("Chrome");
    drillSeries.put("Chrome", drill);
    drill = new DataSeries("Safari versions");
    categories = new String[] { "Safari 5.0", "Safari 4.0", "Safari Win 5.0", "Safari 4.1", "Safari/Maxthon", "Safari 3.1", "Safari 4.1" };
    ys = new Number[] { 4.55, 1.42, 0.23, 0.21, 0.20, 0.19, 0.14 };
    drill.setData(categories, ys);
    drill.setId("Safari");
    drillSeries.put("Safari", drill);
    drill = new DataSeries("Opera versions");
    categories = new String[] { "Opera 9.x", "Opera 10.x", "Opera 11.x" };
    ys = new Number[] { 0.12, 0.37, 1.65 };
    drill.setData(categories, ys);
    drill.setId("Opera");
    drillSeries.put("Opera", drill);
    chart.setDrilldownCallback(event -> getPointDrilldown(event.getItemIndex()));
    add(chart);
}
Also used : DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) XAxis(com.vaadin.flow.component.charts.model.XAxis) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 17 with YAxis

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

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

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

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

YAxis (com.vaadin.flow.component.charts.model.YAxis)37 Configuration (com.vaadin.flow.component.charts.model.Configuration)32 Chart (com.vaadin.flow.component.charts.Chart)31 XAxis (com.vaadin.flow.component.charts.model.XAxis)27 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)21 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)17 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)15 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)11 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)10 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)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 Pane (com.vaadin.flow.component.charts.model.Pane)4 PlotOptionsArea (com.vaadin.flow.component.charts.model.PlotOptionsArea)4 PlotOptionsLine (com.vaadin.flow.component.charts.model.PlotOptionsLine)4 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)4 Crosshair (com.vaadin.flow.component.charts.model.Crosshair)3 PlotBand (com.vaadin.flow.component.charts.model.PlotBand)3