Search in sources :

Example 11 with DataProviderSeries

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

Example 12 with DataProviderSeries

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;
}
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) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 13 with DataProviderSeries

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);
}
Also used : DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) Chart(com.vaadin.addon.charts.Chart)

Example 14 with DataProviderSeries

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));
}
Also used : LocalDateTime(java.time.LocalDateTime) ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 15 with DataProviderSeries

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);
}
Also used : ListDataProvider(com.vaadin.data.provider.ListDataProvider) DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) 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