Search in sources :

Example 1 with PlotOptionsFlags

use of com.vaadin.addon.charts.model.PlotOptionsFlags in project charts by vaadin.

the class FlagsPlacement method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    DataSeries dataSeries = new DataSeries();
    dataSeries.setId(DATA_SERIES_ID);
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        dataSeries.add(item);
    }
    DataSeries flagsOnSeries = new DataSeries();
    flagsOnSeries.setName("Flags on series");
    PlotOptionsFlags plotOptionsFlags = new PlotOptionsFlags();
    plotOptionsFlags.setOnSeries(DATA_SERIES_ID);
    flagsOnSeries.setPlotOptions(plotOptionsFlags);
    for (int i = 30; i < dataSeries.size(); i += 30) {
        flagsOnSeries.add(new FlagItem(dataSeries.get(i).getX(), "On series", "On series flag tooltip"));
    }
    DataSeries flagsOnAxis = new DataSeries();
    flagsOnAxis.setName("Flags on axis");
    flagsOnAxis.setPlotOptions(new PlotOptionsFlags());
    for (int i = 15; i < dataSeries.size(); i += 30) {
        flagsOnAxis.add(new FlagItem(dataSeries.get(i).getX(), "On axis"));
    }
    configuration.setSeries(dataSeries, flagsOnSeries, flagsOnAxis);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(1);
    configuration.setRangeSelector(rangeSelector);
    chart.drawChart(configuration);
    return chart;
}
Also used : StockPrices(com.vaadin.addon.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.addon.charts.model.Configuration) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) PlotOptionsFlags(com.vaadin.addon.charts.model.PlotOptionsFlags) FlagItem(com.vaadin.addon.charts.model.FlagItem) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 2 with PlotOptionsFlags

use of com.vaadin.addon.charts.model.PlotOptionsFlags in project charts by vaadin.

the class ChartDesignWriterTest method writeConfiguration_plotOptionsWithReservedPropertyWord_prefixIsWrittenToReservedProperty.

@Test
public void writeConfiguration_plotOptionsWithReservedPropertyWord_prefixIsWrittenToReservedProperty() {
    DesignContext designContext = new DesignContext();
    Configuration configuration = new Configuration();
    PlotOptionsFlags plotOptionsFlags = new PlotOptionsFlags();
    // plotOptionsFlags.setAllowPointSelect(true);
    plotOptionsFlags.setOnSeries("dataseries");
    configuration.addPlotOptions(plotOptionsFlags);
    Element parent = new Element(Tag.valueOf("test"), "");
    ChartDesignWriter.writeConfigurationToElement(configuration, parent, designContext);
    assertEquals("<plot-options><flags draw-on-series=\"dataseries\"></flags></plot-options>", removeWhitespacesBetweenTags(parent.child(0).toString()));
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) Element(org.jsoup.nodes.Element) DesignContext(com.vaadin.ui.declarative.DesignContext) PlotOptionsFlags(com.vaadin.addon.charts.model.PlotOptionsFlags) Test(org.junit.Test)

Example 3 with PlotOptionsFlags

use of com.vaadin.addon.charts.model.PlotOptionsFlags in project charts by vaadin.

the class ChartTypes method chartTypesFlagsExample.

public void chartTypesFlagsExample() {
    Chart chart = new Chart(ChartType.SPLINE);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("USD to EUR exchange rate");
    configuration.getxAxis().setType(AxisType.DATETIME);
    // A data series to annotate with flags
    DataSeries dataSeries = new DataSeries();
    dataSeries.setId("dataseries");
    dataSeries.addData(new Number[][] { { 1434499200000l, 0.8821 }, { 1434585600000l, 0.8802 }, { 1434672000000l, 0.8808 }, { 1434844800000l, 0.8794 }, { 1434931200000l, 0.8818 }, { 1435017600000l, 0.8952 }, { 1435104000000l, 0.8924 }, { 1435190400000l, 0.8925 }, { 1435276800000l, 0.8955 } });
    // Flags on the data series
    DataSeries flagsOnSeries = new DataSeries();
    flagsOnSeries.setName("Flags on series");
    PlotOptionsFlags plotOptionsFlags = new PlotOptionsFlags();
    plotOptionsFlags.setShape(FlagShape.SQUAREPIN);
    plotOptionsFlags.setOnSeries("dataseries");
    flagsOnSeries.setPlotOptions(plotOptionsFlags);
    flagsOnSeries.add(new FlagItem(1434585600000l, "First Series Flag", "First Series Flag Tooltip Text"));
    flagsOnSeries.add(new FlagItem(1435017600000l, "Second Series Flag"));
    // Flags on the X axis
    DataSeries flagsOnAxis = new DataSeries();
    flagsOnAxis.setPlotOptions(new PlotOptionsFlags());
    flagsOnAxis.setName("Flags on axis");
    flagsOnAxis.add(new FlagItem(1434844800000l, "First Axis Flag", "First Axis Flag Tooltip Text"));
    flagsOnAxis.add(new FlagItem(1435190400000l, "Second Axis Flag"));
    configuration.setSeries(dataSeries, flagsOnSeries, flagsOnAxis);
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsFlags(com.vaadin.addon.charts.model.PlotOptionsFlags) FlagItem(com.vaadin.addon.charts.model.FlagItem) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart)

Example 4 with PlotOptionsFlags

use of com.vaadin.addon.charts.model.PlotOptionsFlags in project charts by vaadin.

the class ChartDesignReaderTest method readConfiguration_plotOptionsWithOnSeriesProperty_onSeriesIsAddedToConfiguration.

@Test
public void readConfiguration_plotOptionsWithOnSeriesProperty_onSeriesIsAddedToConfiguration() {
    Elements elements = createElements("<plot-options><flags draw-on-series=\"dataseries\"></flags></plot-options>");
    Configuration configuration = new Configuration();
    ChartDesignReader.readConfigurationFromElements(elements, configuration);
    assertEquals(1, configuration.getPlotOptions().size());
    assertThat(configuration.getPlotOptions(ChartType.FLAGS), instanceOf(PlotOptionsFlags.class));
    assertEquals("dataseries", ((PlotOptionsFlags) configuration.getPlotOptions(ChartType.FLAGS)).getOnSeries());
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsFlags(com.vaadin.addon.charts.model.PlotOptionsFlags) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Aggregations

Configuration (com.vaadin.addon.charts.model.Configuration)4 PlotOptionsFlags (com.vaadin.addon.charts.model.PlotOptionsFlags)4 Chart (com.vaadin.addon.charts.Chart)2 DataSeries (com.vaadin.addon.charts.model.DataSeries)2 FlagItem (com.vaadin.addon.charts.model.FlagItem)2 Test (org.junit.Test)2 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)1 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)1 RangeSelector (com.vaadin.addon.charts.model.RangeSelector)1 DesignContext (com.vaadin.ui.declarative.DesignContext)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1