Search in sources :

Example 6 with Legend

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

the class Scatter method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.SCATTER);
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Height Versus Weight of 507 Individuals by Gender");
    configuration.setSubTitle("Source: Heinz  2003");
    XAxis xAxis = configuration.getxAxis();
    xAxis.setTitle("Height (cm)");
    xAxis.setStartOnTick(true);
    xAxis.setEndOnTick(true);
    xAxis.setShowLastLabel(true);
    Legend legend = configuration.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setAlign(HorizontalAlign.LEFT);
    legend.setVerticalAlign(VerticalAlign.TOP);
    legend.setX(100);
    legend.setY(70);
    legend.setFloating(true);
    PlotOptionsScatter plotOptionsScatter = new PlotOptionsScatter();
    SeriesTooltip scatterTooltip = plotOptionsScatter.getTooltip();
    scatterTooltip.setHeaderFormat("<b>{series.name}</b><br>\",\"pointFormat\":\"{point.x} cm, {point.y} kg");
    DataSeries femaleSeries = new DataSeries();
    femaleSeries.setName("Female");
    PlotOptionsScatter femalePlotOptions = new PlotOptionsScatter();
    femalePlotOptions.setClassName("femaleSeries");
    femaleSeries.setPlotOptions(femalePlotOptions);
    Number[][] femaleData = getFemaleData();
    for (int i = 0; i < femaleData.length; i++) {
        DataSeriesItem item = new DataSeriesItem(femaleData[i][1], femaleData[i][0]);
        femaleSeries.add(item);
    }
    configuration.addSeries(femaleSeries);
    DataSeries maleSeries = new DataSeries();
    maleSeries.setName("Male");
    PlotOptionsScatter malePlotOptions = new PlotOptionsScatter();
    malePlotOptions.setClassName("maleSeries");
    maleSeries.setPlotOptions(malePlotOptions);
    Number[][] maleData = getMaleData();
    for (int i = 0; i < maleData.length; i++) {
        DataSeriesItem item = new DataSeriesItem(maleData[i][1], maleData[i][0]);
        maleSeries.add(item);
    }
    configuration.addSeries(maleSeries);
    add(chart);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) Configuration(com.vaadin.flow.component.charts.model.Configuration) PlotOptionsScatter(com.vaadin.flow.component.charts.model.PlotOptionsScatter) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip)

Example 7 with Legend

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

the class BoxPlot method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart();
    chart.getConfiguration().setTitle("Box Plot Example");
    Legend legend = new Legend();
    legend.setEnabled(false);
    chart.getConfiguration().setLegend(legend);
    XAxis xaxis = chart.getConfiguration().getxAxis();
    xaxis.setTitle("Experiment No.");
    xaxis.setCategories("1", "2", "3", "4", "5");
    YAxis yAxis = chart.getConfiguration().getyAxis();
    yAxis.setTitle("Observations");
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(932);
    plotLine.setZIndex(0);
    Label label = new Label("Theoretical mean: 932");
    label.setAlign(HorizontalAlign.CENTER);
    plotLine.setLabel(label);
    yAxis.setPlotLines(plotLine);
    final DataSeries observations = new DataSeries();
    observations.setName("Observations");
    // Add PlotBoxItems contain all fields relevant for plot box chart
    observations.add(new BoxPlotItem(760, 801, 848, 895, 965));
    // Example with no arg constructor
    BoxPlotItem plotBoxItem = new BoxPlotItem();
    plotBoxItem.setLow(733);
    plotBoxItem.setLowerQuartile(853);
    plotBoxItem.setMedian(939);
    plotBoxItem.setUpperQuartile(980);
    plotBoxItem.setHigh(1080);
    observations.add(plotBoxItem);
    observations.add(new BoxPlotItem(714, 762, 817, 870, 918));
    observations.add(new BoxPlotItem(724, 802, 806, 871, 950));
    observations.add(new BoxPlotItem(834, 836, 864, 882, 910));
    PlotOptionsBoxplot plotOptions = new PlotOptionsBoxplot();
    SeriesTooltip observationsTooltip = new SeriesTooltip();
    observationsTooltip.setHeaderFormat("<em>Experiment No {point.key}</em><br/>");
    plotOptions.setTooltip(observationsTooltip);
    observations.setPlotOptions(plotOptions);
    chart.getConfiguration().addSeries(observations);
    final DataSeries outlier = new DataSeries();
    outlier.setName("Outlier");
    outlier.add(new DataSeriesItem(0, 644));
    outlier.add(new DataSeriesItem(4, 718));
    outlier.add(new DataSeriesItem(4, 951));
    outlier.add(new DataSeriesItem(4, 969));
    PlotOptionsScatter outlierOptions = new PlotOptionsScatter();
    SeriesTooltip outlierTooltip = new SeriesTooltip();
    outlierTooltip.setPointFormat("Observation: {point.y}");
    outlierOptions.setTooltip(outlierTooltip);
    outlier.setPlotOptions(outlierOptions);
    chart.getConfiguration().addSeries(outlier);
    Checkbox useCustomStyles = new Checkbox("Use custom styling");
    useCustomStyles.addValueChangeListener(e -> {
        PlotOptionsBoxplot options = new PlotOptionsBoxplot();
        if (e.getValue()) {
            options.setClassName("custom-style");
            options.setWhiskerLength("70");
        }
        observations.setPlotOptions(options);
        chart.drawChart(true);
    });
    add(chart, useCustomStyles);
}
Also used : Legend(com.vaadin.flow.component.charts.model.Legend) PlotOptionsScatter(com.vaadin.flow.component.charts.model.PlotOptionsScatter) Label(com.vaadin.flow.component.charts.model.Label) XAxis(com.vaadin.flow.component.charts.model.XAxis) BoxPlotItem(com.vaadin.flow.component.charts.model.BoxPlotItem) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) PlotOptionsBoxplot(com.vaadin.flow.component.charts.model.PlotOptionsBoxplot) PlotLine(com.vaadin.flow.component.charts.model.PlotLine) 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) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip)

Example 8 with Legend

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

Example 9 with Legend

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

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