Search in sources :

Example 1 with Series

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

the class ErrorBar method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    configuration.setTitle("Monthly Rainfall");
    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();
    Labels yLabels = new Labels();
    yLabels.setFormat("{value} mm");
    y.setLabels(yLabels);
    y.setTitle("Rainfall");
    configuration.addyAxis(y);
    Tooltip tooltip = new Tooltip();
    tooltip.setShared(true);
    configuration.setTooltip(tooltip);
    Series rainfall = new ListSeries("Rainfall", 49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
    PlotOptionsColumn rainfallOptions = new PlotOptionsColumn();
    SeriesTooltip rainfallTooltip = new SeriesTooltip();
    rainfallTooltip.setPointFormat("<span style=\"font-weight: bold; color: {series.color}\">" + "{series.name}</span>: <b>{point.y:.1f} mm</b> ");
    rainfallOptions.setTooltip(rainfallTooltip);
    rainfall.setPlotOptions(rainfallOptions);
    configuration.addSeries(rainfall);
    Series error = new RangeSeries("Rainfall error", new Number[] { 48, 51 }, new Number[] { 68, 73 }, new Number[] { 92, 110 }, new Number[] { 128, 136 }, new Number[] { 140, 150 }, new Number[] { 171, 179 }, new Number[] { 135, 143 }, new Number[] { 142, 149 }, new Number[] { 204, 220 }, new Number[] { 189, 199 }, new Number[] { 95, 110 }, new Number[] { 52, 56 });
    PlotOptionsErrorbar errorOptions = new PlotOptionsErrorbar();
    SeriesTooltip errorTooltip = new SeriesTooltip();
    errorTooltip.setPointFormat("(error range: {point.low}-{point.high} mm)<br/>");
    errorOptions.setTooltip(errorTooltip);
    error.setPlotOptions(errorOptions);
    configuration.addSeries(error);
    add(chart);
}
Also used : RangeSeries(com.vaadin.flow.component.charts.model.RangeSeries) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Series(com.vaadin.flow.component.charts.model.Series) PlotOptionsErrorbar(com.vaadin.flow.component.charts.model.PlotOptionsErrorbar) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) RangeSeries(com.vaadin.flow.component.charts.model.RangeSeries) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip) Labels(com.vaadin.flow.component.charts.model.Labels) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) YAxis(com.vaadin.flow.component.charts.model.YAxis) SeriesTooltip(com.vaadin.flow.component.charts.model.SeriesTooltip)

Example 2 with Series

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

the class ConfigurationTest method configurationSetSeriesWithListShouldMakeShallowCopyTest.

@Test
public void configurationSetSeriesWithListShouldMakeShallowCopyTest() {
    Configuration conf = new Configuration();
    List<Series> series = new ArrayList<>();
    conf.setSeries(series);
    series.add(new ListSeries());
    assertEquals(conf.getSeries().size(), 0);
}
Also used : ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Series(com.vaadin.flow.component.charts.model.Series) Configuration(com.vaadin.flow.component.charts.model.Configuration) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Series

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

the class HasItemTest method getSeries.

@Test
public void getSeries() {
    Chart chart = new Chart();
    DataSeries series = new DataSeries();
    chart.getConfiguration().addSeries(series);
    HasItem hasItem = new HasItemTestImpl(chart, 0, 0);
    Series result = hasItem.getSeries();
    Assert.assertEquals(series, result);
}
Also used : TreeSeries(com.vaadin.flow.component.charts.model.TreeSeries) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) ListSeries(com.vaadin.flow.component.charts.model.ListSeries) Series(com.vaadin.flow.component.charts.model.Series) NodeSeries(com.vaadin.flow.component.charts.model.NodeSeries) HasItem(com.vaadin.flow.component.charts.events.HasItem) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Test(org.junit.Test)

Example 4 with Series

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

the class ColumnWithLazyMultiLevelDrilldown method initDemo.

@Override
public void initDemo() {
    log = new Div();
    log.setId("log");
    Div layout = new Div();
    final Chart chart = new Chart(ChartType.COLUMN);
    chart.setId("chart");
    final Configuration conf = chart.getConfiguration();
    conf.setTitle("Global happiness index");
    conf.setSubTitle("Source: www.happyplanetindex.org");
    conf.getLegend().setEnabled(false);
    XAxis x = new XAxis();
    x.setType(AxisType.CATEGORY);
    conf.addxAxis(x);
    YAxis y = new YAxis();
    y.setTitle("Total");
    conf.addyAxis(y);
    PlotOptionsColumn column = new PlotOptionsColumn();
    column.setCursor(Cursor.POINTER);
    column.setDataLabels(new DataLabels(true));
    conf.setPlotOptions(column);
    DataSeries series = new DataSeries();
    series.setName("Regions");
    PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
    plotOptionsColumn.setColorByPoint(true);
    series.setPlotOptions(plotOptionsColumn);
    DataSeriesItem item = new DataSeriesItem("Latin America and Caribbean", 60);
    item.setId("Latin America and Caribbean");
    series.addItemWithDrilldown(item);
    item = new DataSeriesItem("Europe", 50);
    item.setId("Europe");
    series.addItemWithDrilldown(item);
    conf.addSeries(series);
    drillSeries = new HashMap<String, DataSeries>();
    DataSeries drill = new DataSeries("Latin America and Caribbean Countries");
    drill.setId("Latin America and Caribbean Countries");
    item = new DataSeriesItem("Costa Rica", 64);
    item.setId("Costa Rica");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Colombia", 59.8);
    item.setId("Colombia");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Belize", 59.3);
    item.setId("Belize");
    drill.addItemWithDrilldown(item);
    drillSeries.put("Latin America and Caribbean", drill);
    drill = new DataSeries("Europe");
    drill.setId("European Countries");
    item = new DataSeriesItem("Norway", 51.4);
    item.setId("Norway");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Switzerland", 50.3);
    item.setId("Switzerland");
    drill.addItemWithDrilldown(item);
    item = new DataSeriesItem("Portugal", 38.7);
    item.setId("Portugal");
    drill.addItemWithDrilldown(item);
    drillSeries.put("Europe", drill);
    drill = new DataSeries("Details Costa Rica");
    drill.setId("Details Costa Rica");
    final String[] categories = new String[] { "Life Expectancy", "Well-being (0-10)", "Footprint (gha/capita)" };
    Number[] ys = new Number[] { 79.3, 7.3, 2.5 };
    drill.setData(categories, ys);
    drillSeries.put("Costa Rica", drill);
    drill = new DataSeries("Details Colombia");
    drill.setId("Details Colombia");
    ys = new Number[] { 73.7, 6.4, 1.8 };
    drill.setData(categories, ys);
    drillSeries.put("Colombia", drill);
    drill = new DataSeries("Details Belize");
    drill.setId("Details Belize");
    ys = new Number[] { 76.1, 6.5, 2.1 };
    drill.setData(categories, ys);
    drillSeries.put("Belize", drill);
    drill = new DataSeries("Details Norway");
    drill.setId("Details Norway");
    ys = new Number[] { 81.1, 7.6, 4.8 };
    drill.setData(categories, ys);
    drillSeries.put("Norway", drill);
    drill = new DataSeries("Details Switzerland");
    drill.setId("Details Switzerland");
    ys = new Number[] { 82.3, 7.5, 5.0 };
    drill.setData(categories, ys);
    drillSeries.put("Switzerland", drill);
    drill = new DataSeries("Details Portugal");
    drill.setId("Details Portugal");
    ys = new Number[] { 79.5, 4.9, 4.1 };
    drill.setData(categories, ys);
    drillSeries.put("Portugal", drill);
    chart.setDrilldownCallback((DrilldownCallback) event -> {
        log("DrilldownEvent: " + event.getItem().getId());
        return getPointDrilldown(event.getItem());
    });
    chart.addChartDrillupListener(event -> log("ChartDrillupEvent"));
    layout.add(chart, log);
    add(layout);
}
Also used : Text(com.vaadin.flow.component.Text) PlotOptionsColumn(com.vaadin.flow.component.charts.model.PlotOptionsColumn) Chart(com.vaadin.flow.component.charts.Chart) XAxis(com.vaadin.flow.component.charts.model.XAxis) Div(com.vaadin.flow.component.html.Div) HashMap(java.util.HashMap) DrilldownCallback(com.vaadin.flow.component.charts.model.DrilldownCallback) AbstractChartExample(com.vaadin.flow.component.charts.examples.AbstractChartExample) Cursor(com.vaadin.flow.component.charts.model.Cursor) Configuration(com.vaadin.flow.component.charts.model.Configuration) DataLabels(com.vaadin.flow.component.charts.model.DataLabels) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) ChartType(com.vaadin.flow.component.charts.model.ChartType) Map(java.util.Map) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Series(com.vaadin.flow.component.charts.model.Series) YAxis(com.vaadin.flow.component.charts.model.YAxis) AxisType(com.vaadin.flow.component.charts.model.AxisType) DataLabels(com.vaadin.flow.component.charts.model.DataLabels) Configuration(com.vaadin.flow.component.charts.model.Configuration) XAxis(com.vaadin.flow.component.charts.model.XAxis) Div(com.vaadin.flow.component.html.Div) 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 5 with Series

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

the class ServerSideEvents method createControls.

private Component createControls() {
    visibilityToggling = new Checkbox("Disable series visibility toggling");
    visibilityToggling.setId("visibilityToggler");
    visibilityToggling.addValueChangeListener(e -> chart.setVisibilityTogglingDisabled(visibilityToggling.getValue()));
    visibilityToggling.setValue(false);
    final Button firstSeriesVisible = new Button("Hide first series", e -> {
        Series firstSeries = chart.getConfiguration().getSeries().get(0);
        ((AbstractSeries) firstSeries).setVisible(!hideSeries);
        hideSeries = !hideSeries;
    });
    firstSeriesVisible.setId("hideFirstSeries");
    final RadioButtonGroup<Dimension> zoomLevels = new RadioButtonGroup<>();
    zoomLevels.setItems(Dimension.XY, Dimension.X, Dimension.Y);
    zoomLevels.setValue(Dimension.XY);
    zoomLevels.addValueChangeListener(event -> {
        chart.getConfiguration().getChart().setZoomType(zoomLevels.getValue());
        chart.drawChart();
    });
    Button resetHistory = new Button("Reset history");
    resetHistory.setId("resetHistory");
    resetHistory.addClickListener(event -> {
        historyLayout.removeAll();
    });
    Button toggleExtremes = new Button("Toggle Extremes");
    toggleExtremes.setId("toggleExtremes");
    toggleExtremes.addClickListener(e -> {
        if (setExtremes) {
            chart.getConfiguration().getyAxes().getAxis(0).setExtremes(9, 15);
        } else {
            chart.getConfiguration().resetZoom();
        }
        setExtremes = !setExtremes;
    });
    HorizontalLayout controls = new HorizontalLayout();
    controls.setId("controls");
    controls.add(visibilityToggling);
    controls.add(firstSeriesVisible);
    controls.add(zoomLevels);
    controls.add(resetHistory);
    controls.add(toggleExtremes);
    return controls;
}
Also used : PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Series(com.vaadin.flow.component.charts.model.Series) AbstractSeries(com.vaadin.flow.component.charts.model.AbstractSeries) Button(com.vaadin.flow.component.button.Button) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) RadioButtonGroup(com.vaadin.flow.component.radiobutton.RadioButtonGroup) Dimension(com.vaadin.flow.component.charts.model.Dimension) AbstractSeries(com.vaadin.flow.component.charts.model.AbstractSeries) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout)

Aggregations

Series (com.vaadin.flow.component.charts.model.Series)5 Configuration (com.vaadin.flow.component.charts.model.Configuration)3 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)3 ListSeries (com.vaadin.flow.component.charts.model.ListSeries)3 Chart (com.vaadin.flow.component.charts.Chart)2 PlotOptionsColumn (com.vaadin.flow.component.charts.model.PlotOptionsColumn)2 XAxis (com.vaadin.flow.component.charts.model.XAxis)2 YAxis (com.vaadin.flow.component.charts.model.YAxis)2 Test (org.junit.Test)2 Text (com.vaadin.flow.component.Text)1 Button (com.vaadin.flow.component.button.Button)1 HasItem (com.vaadin.flow.component.charts.events.HasItem)1 AbstractChartExample (com.vaadin.flow.component.charts.examples.AbstractChartExample)1 AbstractSeries (com.vaadin.flow.component.charts.model.AbstractSeries)1 AxisType (com.vaadin.flow.component.charts.model.AxisType)1 ChartType (com.vaadin.flow.component.charts.model.ChartType)1 Cursor (com.vaadin.flow.component.charts.model.Cursor)1 DataLabels (com.vaadin.flow.component.charts.model.DataLabels)1 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)1 Dimension (com.vaadin.flow.component.charts.model.Dimension)1