use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.
the class GettingStarted method addColumnsSnippet3.
public Chart addColumnsSnippet3(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.getxAxis().setTitle("Date");
conf.getxAxis().setType(AxisType.DATETIME);
conf.getyAxis().setTitle("Temperature (°C)");
DataProviderSeries<WeatherInfo> humidity = new DataProviderSeries<>(dataProvider);
humidity.setName("Humidity");
humidity.setX(WeatherInfo::getInstant);
humidity.setY(WeatherInfo::getMeanHumidity);
humidity.setPlotOptions(new PlotOptionsColumn());
conf.addSeries(humidity);
conf.addSeries(temp);
YAxis humidityYAxis = new YAxis();
humidityYAxis.setTitle("Humidity (%)");
humidityYAxis.setMin(0);
humidityYAxis.setOpposite(true);
conf.addyAxis(humidityYAxis);
humidity.setyAxis(humidityYAxis);
return chart;
}
use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.
the class ChartDataSeriesJSONSerializationTest method serialize_Instant_ToHigcharts.
@Test
public void serialize_Instant_ToHigcharts() {
LocalDateTime dateTime = LocalDateTime.now();
Collection<TestInstantItem> col = new ArrayList<>();
Instant instant = dateTime.toInstant(ZoneOffset.UTC);
col.add(new TestInstantItem(instant, 80));
DataProvider<TestInstantItem, ?> DataProvider = new ListDataProvider<>(col);
DataProviderSeries<TestInstantItem> chartDataSeries = new DataProviderSeries<>(DataProvider);
chartDataSeries.setX(TestInstantItem::getDate);
chartDataSeries.setY(TestInstantItem::getValue);
String expected = "{\"data\":[[" + instant.toEpochMilli() + ",80]]}";
assertEquals(expected, toJSON(chartDataSeries));
}
use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.
the class ChartDataSeriesJSONSerializationTest method serialize_ContainerWithSeriesPlotOptions_PlotTypeNotSerialized.
@Test
public void serialize_ContainerWithSeriesPlotOptions_PlotTypeNotSerialized() {
PlotOptionsSeries plotOptions = new PlotOptionsSeries();
plotOptions.setShowInLegend(true);
final Pair<ListDataProvider<TestItem>, DataProviderSeries<TestItem>> pair = createTuple();
final DataProviderSeries<TestItem> dataProviderSeries = pair.getT2();
dataProviderSeries.setY(TestItem::getY);
dataProviderSeries.setPlotOptions(plotOptions);
Configuration config = new Configuration();
config.addSeries(dataProviderSeries);
String actual = toJSON(dataProviderSeries);
String expected = "{\"showInLegend\":true,\"data\":[]}";
assertEquals(expected, actual);
}
use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.
the class ChartDataSeriesJSONSerializationTest method serialize_ContainerWithNonUTCDate_DateSerializedAsUTC.
@Test
public void serialize_ContainerWithNonUTCDate_DateSerializedAsUTC() {
final ZonedDateTime nowUTC = ZonedDateTime.of(2010, 10, 10, 10, 39, 00, 00, ZoneId.of("UTC"));
final ZonedDateTime nowEuropeParis = ZonedDateTime.of(2010, 10, 10, 10, 39, 00, 00, ZoneId.of("Europe/Paris"));
final Collection<TestDateItem> colEurope = singletonList(new TestDateItem(nowEuropeParis, 80));
final DataProvider<TestDateItem, ?> dataProviderEurope = new ListDataProvider<>(colEurope);
final DataProviderSeries<TestDateItem> chartDataSeriesEurope = new DataProviderSeries<>(dataProviderEurope);
chartDataSeriesEurope.setX(TestDateItem::getDate);
chartDataSeriesEurope.setY(TestDateItem::getValue);
final Collection<TestDateItem> colUTC = singletonList(new TestDateItem(nowUTC, 80));
final DataProvider<TestDateItem, ?> dataProviderUTC = new ListDataProvider<>(colUTC);
final DataProviderSeries<TestDateItem> chartDataSeriesUTC = new DataProviderSeries<>(dataProviderUTC);
chartDataSeriesUTC.setX(TestDateItem::getDate);
chartDataSeriesUTC.setY(TestDateItem::getValue);
final String actualEurope = toJSON(chartDataSeriesEurope);
final String actualUTC = toJSON(chartDataSeriesUTC);
// not loosing TimeZone
assertNotEquals(actualUTC, actualEurope);
}
use of com.vaadin.data.provider.ListDataProvider in project charts by vaadin.
the class ChartDataSeriesJSONSerializationTest method serialize_ContainerWithLinePlotOptions_PlotOptionsAndTypeSerialized.
@Test
public void serialize_ContainerWithLinePlotOptions_PlotOptionsAndTypeSerialized() {
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setShowInLegend(true);
final Pair<ListDataProvider<TestItem>, DataProviderSeries<TestItem>> pair = createTuple();
final DataProviderSeries<TestItem> dataProviderSeries = pair.getT2();
dataProviderSeries.setY(TestItem::getY);
dataProviderSeries.setPlotOptions(plotOptions);
Configuration config = new Configuration();
config.addSeries(dataProviderSeries);
String actual = toJSON(dataProviderSeries);
String expected = "{\"type\":\"line\",\"showInLegend\":true,\"data\":[]}";
assertEquals(expected, actual);
}
Aggregations