Search in sources :

Example 1 with ListDataProvider

use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.

the class ChartDataSeriesJSONSerializationTest method serialize_ContainerWithNameAndStack_NameAndStackSerialized.

@Test
public void serialize_ContainerWithNameAndStack_NameAndStackSerialized() {
    final Pair<ListDataProvider<TestItem>, DataProviderSeries<TestItem>> pair = createTuple();
    final DataProviderSeries<TestItem> dataProviderSeries = pair.getT2();
    dataProviderSeries.setY(TestItem::getY);
    dataProviderSeries.setName("foo");
    dataProviderSeries.setStack("bar");
    Configuration config = new Configuration();
    config.addSeries(dataProviderSeries);
    String actual = toJSON(dataProviderSeries);
    String expected = "{\"name\":\"foo\",\"stack\":\"bar\",\"data\":[]}";
    assertEquals(expected, actual);
}
Also used : ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) Test(org.junit.Test)

Example 2 with ListDataProvider

use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.

the class GettingStarted method addColumnsSnippet1.

public void addColumnsSnippet1(List<WeatherInfo> weatherInfo) {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    ListDataProvider<WeatherInfo> dataProvider = new ListDataProvider<>(weatherInfo);
    DataProviderSeries<WeatherInfo> humidity = new DataProviderSeries<>(dataProvider);
    humidity.setName("Humidity");
    humidity.setX(WeatherInfo::getInstant);
    humidity.setY(WeatherInfo::getMeanHumidity);
    humidity.setPlotOptions(new PlotOptionsColumn());
    conf.addSeries(humidity);
}
Also used : ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) Chart(com.vaadin.addon.charts.Chart)

Example 3 with ListDataProvider

use of com.vaadin.data.provider.ListDataProvider 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 4 with ListDataProvider

use of com.vaadin.data.provider.ListDataProvider 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 5 with ListDataProvider

use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.

the class GettingStarted method combinationChartPreparationsSnippet3.

public Chart combinationChartPreparationsSnippet3(ChartsData data) {
    Chart chart = new Chart();
    Configuration conf = chart.getConfiguration();
    conf.setTitle("Turku, Finland 2013");
    conf.getChart().setType(ChartType.LINE);
    ListDataProvider<WeatherInfo> dataProvider = new ListDataProvider<>(data.getWeatherData());
    DataProviderSeries<WeatherInfo> temp = new DataProviderSeries<>(dataProvider);
    temp.setName("Temperature");
    temp.setX(WeatherInfo::getInstant);
    temp.setY(WeatherInfo::getMaxTemp);
    conf.addSeries(temp);
    conf.getxAxis().setTitle("Date");
    conf.getxAxis().setType(AxisType.DATETIME);
    conf.getyAxis().setTitle("Temperature (°C)");
    return chart;
}
Also used : ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) Chart(com.vaadin.addon.charts.Chart)

Aggregations

DataProviderSeries (com.vaadin.addon.charts.model.DataProviderSeries)10 ListDataProvider (com.vaadin.data.provider.ListDataProvider)10 Configuration (com.vaadin.addon.charts.model.Configuration)8 Chart (com.vaadin.addon.charts.Chart)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)2 YAxis (com.vaadin.addon.charts.model.YAxis)2 LocalDateTime (java.time.LocalDateTime)2 PlotOptionsArea (com.vaadin.addon.charts.model.PlotOptionsArea)1 PlotOptionsLine (com.vaadin.addon.charts.model.PlotOptionsLine)1 PlotOptionsSeries (com.vaadin.addon.charts.model.PlotOptionsSeries)1 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)1 Title (com.vaadin.addon.charts.model.Title)1 XAxis (com.vaadin.addon.charts.model.XAxis)1 Instant (java.time.Instant)1 ZonedDateTime (java.time.ZonedDateTime)1