Search in sources :

Example 6 with DataProviderSeries

use of com.vaadin.addon.charts.model.DataProviderSeries in project charts by vaadin.

the class ChartWithExternalDataProvider method createChartDataSeries2.

private DataProviderSeries<Order> createChartDataSeries2(DataProvider<Order, ?> dataProvider) {
    DataProviderSeries<Order> chartDS = new DataProviderSeries<>(dataProvider);
    chartDS.setName("Order item prices");
    chartDS.setPlotOptions(new PlotOptionsColumn());
    chartDS.setY(order -> order.getItemPrice().intValue());
    chartDS.setPointName(Order::getDescription);
    return chartDS;
}
Also used : DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn)

Example 7 with DataProviderSeries

use of com.vaadin.addon.charts.model.DataProviderSeries in project charts by vaadin.

the class ChartWithExternalDataProvider method createChartDataSeries1.

private DataProviderSeries<Order> createChartDataSeries1(DataProvider<Order, ?> dataProvider) {
    DataProviderSeries<Order> chartDS = new DataProviderSeries<>(dataProvider);
    chartDS.setName("Order item quantities");
    chartDS.setPlotOptions(new PlotOptionsPie());
    chartDS.setY(Order::getQuantity);
    chartDS.setPointName(Order::getDescription);
    return chartDS;
}
Also used : DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) PlotOptionsPie(com.vaadin.addon.charts.model.PlotOptionsPie)

Example 8 with DataProviderSeries

use of com.vaadin.addon.charts.model.DataProviderSeries in project charts by vaadin.

the class DataProviderSeriesWithSpline method getChart.

@Override
protected Component getChart() {
    // Create container with two points
    Collection<TestItem> col = new ArrayList<>();
    DataProvider<TestItem, ?> ds = new ListDataProvider<>(col);
    LocalDateTime dateTime = LocalDateTime.of(2013, 3, 22, 12, 00);
    col.add(new TestItem(dateTime.toInstant(ZoneOffset.UTC), 5));
    dateTime = dateTime.plusDays(1);
    col.add(new TestItem(dateTime.toInstant(ZoneOffset.UTC), 10));
    dateTime = dateTime.plusDays(1);
    col.add(new TestItem(dateTime.toInstant(ZoneOffset.UTC), 5));
    DataProviderSeries<TestItem> chartDataSeries = new DataProviderSeries<>(ds);
    chartDataSeries.setX(TestItem::getDate);
    chartDataSeries.setY(TestItem::getValue);
    // Create chart and render
    Chart chart = new Chart();
    // Create chart config
    Configuration config = chart.getConfiguration();
    config.getxAxis().setType(AxisType.DATETIME);
    // Wrap container in a container data series
    chartDataSeries.setPlotOptions(new PlotOptionsSpline());
    // Add points to series
    config.addSeries(chartDataSeries);
    chart.setSizeFull();
    chart.drawChart(config);
    return chart;
}
Also used : LocalDateTime(java.time.LocalDateTime) ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) ArrayList(java.util.ArrayList) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) Chart(com.vaadin.addon.charts.Chart)

Example 9 with DataProviderSeries

use of com.vaadin.addon.charts.model.DataProviderSeries in project charts by vaadin.

the class ColoredContainerSeries method getChart.

@Override
protected Component getChart() {
    Chart chart = new Chart(ChartType.AREA);
    Configuration conf = chart.getConfiguration();
    conf.setTitle(new Title("Colored ContainerDataSeries"));
    conf.addxAxis(new XAxis());
    YAxis yAxis = new YAxis();
    yAxis.setTitle("Numbers");
    conf.addyAxis(yAxis);
    Collection<Test> col = new ArrayList<>();
    col.add(new Test(10, "TEN"));
    col.add(new Test(11, "ELEVEN"));
    col.add(new Test(12, "TWELVE"));
    DataProvider<Test, ?> ds = new ListDataProvider<>(col);
    DataProviderSeries<Test> chartDS = new DataProviderSeries<>(ds);
    chartDS.setName("Test Series");
    chartDS.setY(Test::getNumber);
    chartDS.setPointName(Test::getName);
    PlotOptionsArea plotOptions = new PlotOptionsArea();
    plotOptions.setFillColor(SolidColor.CORNFLOWERBLUE);
    plotOptions.setColor(SolidColor.GOLDENROD);
    chartDS.setPlotOptions(plotOptions);
    // conf.setPlotOptions(plotOptions);
    conf.setSeries(chartDS);
    chart.drawChart(conf);
    return chart;
}
Also used : ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) ArrayList(java.util.ArrayList) Title(com.vaadin.addon.charts.model.Title) XAxis(com.vaadin.addon.charts.model.XAxis) PlotOptionsArea(com.vaadin.addon.charts.model.PlotOptionsArea) Chart(com.vaadin.addon.charts.Chart) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 10 with DataProviderSeries

use of com.vaadin.addon.charts.model.DataProviderSeries in project charts by vaadin.

the class ConfigurationTest method setSeries_containerDataSeriesWithName_NameAppearsInLegend.

@Test
public void setSeries_containerDataSeriesWithName_NameAppearsInLegend() {
    Configuration conf = new Configuration();
    conf.getChart().setType(ChartType.AREA);
    XAxis xAxis = new XAxis();
    xAxis.setCategories("A", "B", "C", "D", "E");
    conf.addxAxis(xAxis);
    YAxis yAxis = new YAxis();
    AxisTitle title = new AxisTitle();
    title.setText("Numbers");
    yAxis.setTitle(title);
    conf.addyAxis(yAxis);
    DataProviderSeries<Pair> ds = new DataProviderSeries<>(createDataProvider());
    ds.setName("Test Series1");
    ds.setY(Pair::getValue);
    ds.setPointName(Pair::getName);
    // if a 'plotOptionsArea' is not set, the name of this series will not
    // be shown in legend
    // containerDataSeries1.setPlotOptions(new PlotOptionsArea());
    conf.setSeries(ds);
    Assert.assertTrue(toJSON(conf).contains("Test Series1"));
}
Also used : DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) XAxis(com.vaadin.addon.charts.model.XAxis) YAxis(com.vaadin.addon.charts.model.YAxis) Test(org.junit.Test)

Aggregations

DataProviderSeries (com.vaadin.addon.charts.model.DataProviderSeries)17 Configuration (com.vaadin.addon.charts.model.Configuration)12 ListDataProvider (com.vaadin.data.provider.ListDataProvider)10 Chart (com.vaadin.addon.charts.Chart)8 Test (org.junit.Test)6 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)4 YAxis (com.vaadin.addon.charts.model.YAxis)4 ArrayList (java.util.ArrayList)3 PlotOptionsSeries (com.vaadin.addon.charts.model.PlotOptionsSeries)2 XAxis (com.vaadin.addon.charts.model.XAxis)2 LocalDateTime (java.time.LocalDateTime)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)1 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)1 CLOSE_PROPERTY (com.vaadin.addon.charts.model.DataProviderSeries.CLOSE_PROPERTY)1 HIGH_PROPERTY (com.vaadin.addon.charts.model.DataProviderSeries.HIGH_PROPERTY)1