Search in sources :

Example 1 with PlotOptionsOhlc

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

the class ChartTypes method chartTypesOhlcSnippet2.

public void chartTypesOhlcSnippet2() {
    Chart chart = new Chart(ChartType.OHLC);
    Configuration configuration = chart.getConfiguration();
    // Create a DataProvider filled with stock price data
    DataProvider<OhlcData, ?> dataProvider = initDataProvider();
    // Wrap the container in a data series
    DataProviderSeries<OhlcData> dataSeries = new DataProviderSeries<>(dataProvider);
    dataSeries.setX(OhlcData::getDate);
    dataSeries.setLow(OhlcData::getLow);
    dataSeries.setHigh(OhlcData::getHigh);
    dataSeries.setClose(OhlcData::getClose);
    dataSeries.setOpen(OhlcData::getOpen);
    PlotOptionsOhlc plotOptionsOhlc = new PlotOptionsOhlc();
    plotOptionsOhlc.setTurboThreshold(0);
    dataSeries.setPlotOptions(plotOptionsOhlc);
    configuration.setSeries(dataSeries);
}
Also used : DataProviderSeries(com.vaadin.addon.charts.model.DataProviderSeries) Configuration(com.vaadin.addon.charts.model.Configuration) PlotOptionsOhlc(com.vaadin.addon.charts.model.PlotOptionsOhlc) Chart(com.vaadin.addon.charts.Chart)

Example 2 with PlotOptionsOhlc

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

the class Ohlc method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart(ChartType.OHLC);
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    DataSeries dataSeries = new DataSeries();
    PlotOptionsOhlc plotOptionsOhlc = new PlotOptionsOhlc();
    DataGrouping grouping = new DataGrouping();
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.WEEK, 1));
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.MONTH, 1, 2, 3, 4, 6));
    plotOptionsOhlc.setDataGrouping(grouping);
    dataSeries.setPlotOptions(plotOptionsOhlc);
    for (StockPrices.OhlcData data : StockPrices.fetchAaplOhlcPrice()) {
        OhlcItem item = new OhlcItem();
        item.setX(data.getDate());
        item.setLow(data.getLow());
        item.setHigh(data.getHigh());
        item.setClose(data.getClose());
        item.setOpen(data.getOpen());
        dataSeries.add(item);
    }
    configuration.setSeries(dataSeries);
    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) TimeUnitMultiples(com.vaadin.addon.charts.model.TimeUnitMultiples) OhlcItem(com.vaadin.addon.charts.model.OhlcItem) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) DataGrouping(com.vaadin.addon.charts.model.DataGrouping) DataSeries(com.vaadin.addon.charts.model.DataSeries) PlotOptionsOhlc(com.vaadin.addon.charts.model.PlotOptionsOhlc) Chart(com.vaadin.addon.charts.Chart)

Aggregations

Chart (com.vaadin.addon.charts.Chart)2 Configuration (com.vaadin.addon.charts.model.Configuration)2 PlotOptionsOhlc (com.vaadin.addon.charts.model.PlotOptionsOhlc)2 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)1 DataGrouping (com.vaadin.addon.charts.model.DataGrouping)1 DataProviderSeries (com.vaadin.addon.charts.model.DataProviderSeries)1 DataSeries (com.vaadin.addon.charts.model.DataSeries)1 OhlcItem (com.vaadin.addon.charts.model.OhlcItem)1 RangeSelector (com.vaadin.addon.charts.model.RangeSelector)1 TimeUnitMultiples (com.vaadin.addon.charts.model.TimeUnitMultiples)1