Search in sources :

Example 31 with YAxis

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

the class AreaChart method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("First Chart for Flow");
    chart.getConfiguration().getChart().setType(ChartType.AREA);
    add(chart);
    configuration.addSeries(new ListSeries("Tokyo", 20, 12, 34, 23, 65, 8, 4, 7, 76, 19, 20, 8));
    configuration.addSeries(new ListSeries("Miami", 34, 29, 23, 65, 8, 4, 7, 7, 59, 8, 9, 19));
    XAxis x = new XAxis();
    x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    configuration.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    y.setTitle("Rainfall (mm)");
    configuration.addyAxis(y);
    NativeButton changeTitleButton = new NativeButton();
    changeTitleButton.setId("change_title");
    changeTitleButton.setText("Change title");
    changeTitleButton.addClickListener(e -> {
        configuration.setTitle("First Chart for Flow - title changed");
        chart.drawChart();
    });
    add(changeTitleButton);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Configuration(com.vaadin.flow.component.charts.model.Configuration) 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 32 with YAxis

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

the class BarChart method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Historic World Population by Region");
    configuration.setSubTitle("Source: <a href=\"https://en.wikipedia.org/wiki/World_population\">Wikipedia.org</a>");
    chart.getConfiguration().getChart().setType(ChartType.BAR);
    configuration.addSeries(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
    configuration.addSeries(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
    configuration.addSeries(new ListSeries("Year 2000", 814, 841, 3714, 727, 31));
    configuration.addSeries(new ListSeries("Year 2016", 1216, 1001, 4436, 738, 40));
    XAxis x = new XAxis();
    x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
    configuration.addxAxis(x);
    YAxis y = new YAxis();
    y.setMin(0);
    AxisTitle yTitle = new AxisTitle();
    yTitle.setText("Population (millions)");
    yTitle.setAlign(VerticalAlign.HIGH);
    y.setTitle(yTitle);
    configuration.addyAxis(y);
    Tooltip tooltip = new Tooltip();
    tooltip.setValueSuffix(" millions");
    configuration.setTooltip(tooltip);
    PlotOptionsBar plotOptions = new PlotOptionsBar();
    DataLabels dataLabels = new DataLabels();
    dataLabels.setEnabled(true);
    plotOptions.setDataLabels(dataLabels);
    configuration.setPlotOptions(plotOptions);
    add(chart);
}
Also used : DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) PlotOptionsBar(com.vaadin.flow.component.charts.model.PlotOptionsBar) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 33 with YAxis

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

the class ColumnWithNativeLazyDrilldown 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));
    // column.getDataLabels().setFormatter("this.y +'%'");
    conf.setPlotOptions(column);
    Tooltip tooltip = new Tooltip();
    tooltip.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
    tooltip.setPointFormat("<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>");
    conf.setTooltip(tooltip);
    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);
    item.setId("MSIE");
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Firefox", 21.63);
    item.setId("Firefox");
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Chrome", 11.94);
    item.setId("Chrome");
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Safari", 7.15);
    item.setId("Safari");
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Opera", 2.14);
    item.setId("Opera");
    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);
    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);
    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);
    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);
    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);
    drillSeries.put("Opera", drill);
    chart.setDrilldownCallback(event -> getPointDrilldown(event.getItem()));
    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 34 with YAxis

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

the class ColumnWithNativeLazyDrilldownMultipleSeries 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.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
    tooltip.setPointFormat("<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>");
    conf.setTooltip(tooltip);
    createSeries(1);
    createSeries(2);
    drillSeries = new HashMap<>();
    addDrillSeries(1);
    addDrillSeries(2);
    chart.setDrilldownCallback(event -> getPointDrilldown(event.getItem()));
    add(chart);
}
Also used : DataLabels(com.vaadin.flow.component.charts.model.DataLabels) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 35 with YAxis

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

the class WindRose method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.COLUMN);
    Configuration conf = chart.getConfiguration();
    conf.getChart().setPolar(true);
    conf.setTitle("Wind rose for South Shore Met Station, Oregon");
    conf.setSubTitle("Source: or.water.usgs.gov");
    XAxis xAxis = conf.getxAxis();
    xAxis.setCategories("N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW");
    YAxis yAxis = conf.getyAxis();
    yAxis.setReversedStacks(false);
    yAxis.setTitle("Frequency (%)");
    yAxis.setMin(0);
    yAxis.setEndOnTick(false);
    yAxis.setShowLastLabel(true);
    yAxis.getLabels().setFormatter("function() { return this.value + '%';}");
    conf.getTooltip().setValueSuffix("%");
    conf.getPane().setSize("85%");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setStacking(Stacking.NORMAL);
    plotOptionsColumn.setGroupPadding(0);
    plotOptionsColumn.setPointPlacement(PointPlacement.ON);
    conf.setPlotOptions(plotOptionsColumn);
    Legend legend = conf.getLegend();
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setY(100);
    legend.setLayout(LayoutDirection.VERTICAL);
    DataSeries series = new DataSeries();
    series.setName("&lt; 0.5 m/s");
    series.setData(1.81, 0.62, 0.82, 0.59, 0.62, 1.22, 1.61, 2.04, 2.66, 2.96, 2.53, 1.97, 1.64, 1.32, 1.58, 1.51);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("0.5-2 m/s");
    series.setData(1.78, 1.09, 0.82, 1.22, 2.2, 2.01, 3.06, 3.42, 4.74, 4.14, 4.01, 2.66, 1.71, 2.4, 4.28, 5);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("2-4 m/s");
    series.setData(0.16, 0, 0.07, 0.07, 0.49, 1.55, 2.37, 1.97, 0.43, 0.26, 1.22, 1.97, 0.92, 0.99, 1.28, 1.32);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("4-6 m/s");
    series.setData(0, 0, 0, 0, 0, 0.3, 2.14, 0.86, 0, 0, 0.49, 0.79, 1.45, 1.61, 0.76, 0.13);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("6-8 m/s");
    series.setData(0, 0, 0, 0, 0, 0.13, 1.74, 0.53, 0, 0, 0.13, 0.3, 0.26, 0.33, 0.66, 0.23);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("8-10 m/s");
    series.setData(0, 0, 0, 0, 0, 0, 0.39, 0.49, 0, 0, 0, 0, 0.1, 0, 0.69, 0.13);
    conf.addSeries(series);
    series = new DataSeries();
    series.setName("&gt; 10 m/s");
    series.setData(0, 0, 0, 0, 0, 0, 0.13, 0, 0, 0, 0, 0, 0, 0, 0.03, 0.07);
    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) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) 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