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