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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations