Search in sources :

Example 1 with DataGrouping

use of com.vaadin.flow.component.charts.model.DataGrouping in project flow-components by vaadin.

the class Candlestick method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.CANDLESTICK);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    DataSeries dataSeries = new DataSeries();
    PlotOptionsCandlestick plotOptionsCandlestick = new PlotOptionsCandlestick();
    DataGrouping grouping = new DataGrouping();
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.WEEK, 1));
    grouping.addUnit(new TimeUnitMultiples(TimeUnit.MONTH, 1, 2, 3, 4, 6));
    plotOptionsCandlestick.setDataGrouping(grouping);
    dataSeries.setPlotOptions(plotOptionsCandlestick);
    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(4);
    configuration.setRangeSelector(rangeSelector);
    chart.setTimeline(true);
    add(chart);
}
Also used : PlotOptionsCandlestick(com.vaadin.flow.component.charts.model.PlotOptionsCandlestick) StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) TimeUnitMultiples(com.vaadin.flow.component.charts.model.TimeUnitMultiples) OhlcItem(com.vaadin.flow.component.charts.model.OhlcItem) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) DataGrouping(com.vaadin.flow.component.charts.model.DataGrouping) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart)

Example 2 with DataGrouping

use of com.vaadin.flow.component.charts.model.DataGrouping in project flow-components by vaadin.

the class OHLC method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.OHLC);
    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.setTimeline(true);
    add(chart);
}
Also used : StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) TimeUnitMultiples(com.vaadin.flow.component.charts.model.TimeUnitMultiples) OhlcItem(com.vaadin.flow.component.charts.model.OhlcItem) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) DataGrouping(com.vaadin.flow.component.charts.model.DataGrouping) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) PlotOptionsOhlc(com.vaadin.flow.component.charts.model.PlotOptionsOhlc) Chart(com.vaadin.flow.component.charts.Chart)

Aggregations

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