Search in sources :

Example 6 with ListDataProvider

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;
}
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 7 with ListDataProvider

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));
}
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 8 with ListDataProvider

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

Example 9 with ListDataProvider

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

Example 10 with ListDataProvider

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

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