Search in sources :

Example 1 with RangeSelector

use of com.vaadin.flow.component.charts.model.RangeSelector 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 RangeSelector

use of com.vaadin.flow.component.charts.model.RangeSelector 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)

Example 3 with RangeSelector

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

the class ColumnRange method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart(ChartType.COLUMNRANGE);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("Temperature variation by day");
    DataSeries dataSeries = new DataSeries("Temperatures");
    for (StockPrices.RangeData data : StockPrices.fetchDailyTempRanges()) {
        dataSeries.add(new DataSeriesItem(data.getDate(), data.getMin(), data.getMax()));
    }
    configuration.setSeries(dataSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(2);
    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) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Example 4 with RangeSelector

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

the class CompareMultipleSeries method initDemo.

@Override
public void initDemo() {
    final Chart chart = new Chart();
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    YAxis yAxis = new YAxis();
    Labels label = new Labels();
    label.setFormatter("function() { return (this.value > 0 ? ' + ' : '') + this.value + '%'; }");
    yAxis.setLabels(label);
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setPointFormat("<span>{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>");
    tooltip.setValueDecimals(2);
    configuration.setTooltip(tooltip);
    DataSeries aaplSeries = new DataSeries();
    aaplSeries.setName("AAPL");
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    DataSeries googSeries = new DataSeries();
    googSeries.setName("GOOG");
    for (StockPrices.PriceData data : StockPrices.fetchGoogPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        googSeries.add(item);
    }
    DataSeries msftSeries = new DataSeries();
    msftSeries.setName("MSFT");
    for (StockPrices.PriceData data : StockPrices.fetchMsftPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        msftSeries.add(item);
    }
    configuration.setSeries(aaplSeries, googSeries, msftSeries);
    PlotOptionsSeries plotOptionsSeries = new PlotOptionsSeries();
    plotOptionsSeries.setCompare(Compare.PERCENT);
    configuration.setPlotOptions(plotOptionsSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    configuration.setRangeSelector(rangeSelector);
    add(chart);
}
Also used : StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) Tooltip(com.vaadin.flow.component.charts.model.Tooltip) Labels(com.vaadin.flow.component.charts.model.Labels) PlotLine(com.vaadin.flow.component.charts.model.PlotLine) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem) PlotOptionsSeries(com.vaadin.flow.component.charts.model.PlotOptionsSeries) YAxis(com.vaadin.flow.component.charts.model.YAxis)

Example 5 with RangeSelector

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

the class Spline method initDemo.

@Override
public void initDemo() {
    Chart chart = new Chart(ChartType.SPLINE);
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.getTitle().setText("AAPL Stock Price");
    configuration.getTooltip().setEnabled(true);
    DataSeries dataSeries = new DataSeries();
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        dataSeries.add(item);
    }
    configuration.addSeries(dataSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(1);
    configuration.setRangeSelector(rangeSelector);
    add(chart);
}
Also used : StockPrices(com.vaadin.flow.component.charts.examples.timeline.util.StockPrices) Configuration(com.vaadin.flow.component.charts.model.Configuration) RangeSelector(com.vaadin.flow.component.charts.model.RangeSelector) DataSeries(com.vaadin.flow.component.charts.model.DataSeries) Chart(com.vaadin.flow.component.charts.Chart) DataSeriesItem(com.vaadin.flow.component.charts.model.DataSeriesItem)

Aggregations

Chart (com.vaadin.flow.component.charts.Chart)5 StockPrices (com.vaadin.flow.component.charts.examples.timeline.util.StockPrices)5 Configuration (com.vaadin.flow.component.charts.model.Configuration)5 DataSeries (com.vaadin.flow.component.charts.model.DataSeries)5 RangeSelector (com.vaadin.flow.component.charts.model.RangeSelector)5 DataSeriesItem (com.vaadin.flow.component.charts.model.DataSeriesItem)3 DataGrouping (com.vaadin.flow.component.charts.model.DataGrouping)2 OhlcItem (com.vaadin.flow.component.charts.model.OhlcItem)2 TimeUnitMultiples (com.vaadin.flow.component.charts.model.TimeUnitMultiples)2 Labels (com.vaadin.flow.component.charts.model.Labels)1 PlotLine (com.vaadin.flow.component.charts.model.PlotLine)1 PlotOptionsCandlestick (com.vaadin.flow.component.charts.model.PlotOptionsCandlestick)1 PlotOptionsOhlc (com.vaadin.flow.component.charts.model.PlotOptionsOhlc)1 PlotOptionsSeries (com.vaadin.flow.component.charts.model.PlotOptionsSeries)1 Tooltip (com.vaadin.flow.component.charts.model.Tooltip)1 YAxis (com.vaadin.flow.component.charts.model.YAxis)1