Search in sources :

Example 1 with OhlcItem

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

the class ChartTypes method chartTypesOhlcSnippet1.

public void chartTypesOhlcSnippet1() {
    Chart chart = new Chart(ChartType.OHLC);
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    DataSeries dataSeries = new DataSeries();
    Collection<OhlcData> dataBank = null;
    for (OhlcData data : dataBank) {
        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);
    chart.drawChart(configuration);
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) OhlcItem(com.vaadin.addon.charts.model.OhlcItem) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart)

Example 2 with OhlcItem

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

the class Candlestick method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart(ChartType.CANDLESTICK);
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    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.drawChart(configuration);
    return chart;
}
Also used : PlotOptionsCandlestick(com.vaadin.addon.charts.model.PlotOptionsCandlestick) 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) Chart(com.vaadin.addon.charts.Chart)

Example 3 with OhlcItem

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

Example 4 with OhlcItem

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

the class DataSeriesItemJSONSerializationTest method toJSON_OhlcItem_ItemSerializedAsArray.

@Test
public void toJSON_OhlcItem_ItemSerializedAsArray() {
    OhlcItem item = new OhlcItem(1, 2, 3, 4, 5);
    DataSeries series = new DataSeries();
    series.add(item);
    String expected = "{\"data\":[[1,2,3,4,5]]}";
    assertEquals(expected, toJSON(series));
}
Also used : OhlcItem(com.vaadin.addon.charts.model.OhlcItem) DataSeries(com.vaadin.addon.charts.model.DataSeries) Test(org.junit.Test)

Example 5 with OhlcItem

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

the class DataSeriesItemJSONSerializationTest method toJSON_OhlcItemCustomized_ItemSerializedAsArray.

@Test
public void toJSON_OhlcItemCustomized_ItemSerializedAsArray() {
    OhlcItem item = new OhlcItem(1, 2, 3, 4, 5);
    item.setCursor("move");
    DataSeries series = new DataSeries();
    series.add(item);
    String expected = "{\"data\":[{\"x\":1,\"low\":4,\"high\":3,\"cursor\":\"move\",\"open\":2,\"close\":5}]}";
    assertEquals(expected, toJSON(series));
}
Also used : OhlcItem(com.vaadin.addon.charts.model.OhlcItem) DataSeries(com.vaadin.addon.charts.model.DataSeries) Test(org.junit.Test)

Aggregations

DataSeries (com.vaadin.addon.charts.model.DataSeries)5 OhlcItem (com.vaadin.addon.charts.model.OhlcItem)5 Chart (com.vaadin.addon.charts.Chart)3 Configuration (com.vaadin.addon.charts.model.Configuration)3 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)2 DataGrouping (com.vaadin.addon.charts.model.DataGrouping)2 RangeSelector (com.vaadin.addon.charts.model.RangeSelector)2 TimeUnitMultiples (com.vaadin.addon.charts.model.TimeUnitMultiples)2 Test (org.junit.Test)2 PlotOptionsCandlestick (com.vaadin.addon.charts.model.PlotOptionsCandlestick)1 PlotOptionsOhlc (com.vaadin.addon.charts.model.PlotOptionsOhlc)1