use of com.vaadin.addon.charts.model.DataProviderSeries 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;
}
use of com.vaadin.addon.charts.model.DataProviderSeries 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.addon.charts.model.DataProviderSeries in project charts by vaadin.
the class ChartData method dataProviderSeriesSnippet3.
public void dataProviderSeriesSnippet3(Configuration conf, DataProvider<Order, ?> dataProvider) {
// Create a chart and use the data provider
Chart chart = new Chart(ChartType.COLUMN);
Configuration configuration = chart.getConfiguration();
DataProviderSeries<Order> series = new DataProviderSeries<>(dataProvider, Order::getTotalPrice);
configuration.addSeries(series);
}
use of com.vaadin.addon.charts.model.DataProviderSeries 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.addon.charts.model.DataProviderSeries 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);
}
Aggregations