Search in sources :

Example 1 with FlagItem

use of com.vaadin.addon.charts.model.FlagItem 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 FlagItem

use of com.vaadin.addon.charts.model.FlagItem 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)

Aggregations

Chart (com.vaadin.addon.charts.Chart)2 Configuration (com.vaadin.addon.charts.model.Configuration)2 DataSeries (com.vaadin.addon.charts.model.DataSeries)2 FlagItem (com.vaadin.addon.charts.model.FlagItem)2 PlotOptionsFlags (com.vaadin.addon.charts.model.PlotOptionsFlags)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