Search in sources :

Example 1 with Legend

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

the class Spiderweb method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    configuration.getChart().setPolar(true);
    configuration.setTitle("Budget vs spending");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setCategories("Sales", "Marketing", "Development", "Customer Support", "Information Technology", "Administration");
    xAxis.setTickmarkPlacement(TickmarkPlacement.ON);
    YAxis yAxis = configuration.getyAxis();
    yAxis.setGridLineInterpolation("polygon");
    yAxis.setMin(0);
    Tooltip tooltip = configuration.getTooltip();
    tooltip.setShared(true);
    tooltip.setPointFormat("<span style=\"color:{series.color}\">{series.name}: <b>${point.y:,.0f}</b><br/>");
    Legend legend = configuration.getLegend();
    legend.setAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setY(70);
    ListSeries allocatedBudget = new ListSeries("Allocated Budget", 43000, 19000, 60000, 35000, 17000, 10000);
    configuration.addSeries(allocatedBudget);
    ListSeries actualSpending = new ListSeries("Actual Spending", 50000, 39000, 42000, 31000, 26000, 14000);
    configuration.addSeries(actualSpending);
    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) 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 2 with Legend

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

the class AreaSpline method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.AREASPLINE);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Average fruit consumption during one week"));
    Legend legend = new Legend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setFloating(true);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(150);
    legend.setY(100);
    conf.setLegend(legend);
    XAxis xAxis = new XAxis();
    xAxis.setCategories(new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" });
    PlotBand plotBand = new PlotBand(4.5, 6.5, SolidColor.BLUE);
    plotBand.setZIndex(1);
    xAxis.setPlotBands(plotBand);
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    yAxis.setTitle(new AxisTitle("Fruit units"));
    conf.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    // Customize tooltip formatting
    tooltip.setShared(true);
    tooltip.setValueSuffix(" units");
    conf.setTooltip(tooltip);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    conf.setPlotOptions(plotOptions);
    ListSeries o = new ListSeries("John", 3, 4, 3, 5, 4, 10);
    // You can also add values separately
    o.addData(12);
    conf.addSeries(o);
    conf.addSeries(new ListSeries("Jane", 1, 3, 4, 3, 3, 5, 4));
    add(chart);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsArea(com.vaadin.flow.component.charts.model.PlotOptionsArea) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Title(com.vaadin.flow.component.charts.model.Title) AxisTitle(com.vaadin.flow.component.charts.model.AxisTitle) PlotBand(com.vaadin.flow.component.charts.model.PlotBand) 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 3 with Legend

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

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

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

Aggregations

Legend (com.vaadin.flow.component.charts.model.Legend)9 Chart (com.vaadin.flow.component.charts.Chart)8 Configuration (com.vaadin.flow.component.charts.model.Configuration)8 YAxis (com.vaadin.flow.component.charts.model.YAxis)8 XAxis (com.vaadin.flow.component.charts.model.XAxis)6 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)5 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)4 AxisTitle (com.vaadin.flow.component.charts.model.AxisTitle)3 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)3 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)2 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)2 PlotOptionsScatter (com.vaadin.flow.component.charts.model.PlotOptionsScatter)2 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)2 SeriesTooltip (com.vaadin.flow.component.charts.model.SeriesTooltip)2 BoxPlotItem (com.vaadin.flow.component.charts.model.BoxPlotItem)1 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)1 Label (com.vaadin.flow.component.charts.model.Label)1 Labels (com.vaadin.flow.component.charts.model.Labels)1 PlotBand (com.vaadin.flow.component.charts.model.PlotBand)1 PlotLine (com.vaadin.flow.component.charts.model.PlotLine)1