Search in sources :

Example 1 with RangeSelector

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

the class CompareMultipleSeries 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");
    YAxis yAxis = new YAxis();
    Labels label = new Labels();
    label.setFormatter("(this.value > 0 ? ' + ' : '') + this.value + '%'");
    yAxis.setLabels(label);
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    plotLine.setColor(SolidColor.SILVER);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    Tooltip tooltip = new Tooltip();
    tooltip.setPointFormat("<span style=\"color:{series.color}\">{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(PERCENT);
    configuration.setPlotOptions(plotOptionsSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    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) Tooltip(com.vaadin.addon.charts.model.Tooltip) Labels(com.vaadin.addon.charts.model.Labels) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) PlotOptionsSeries(com.vaadin.addon.charts.model.PlotOptionsSeries) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 2 with RangeSelector

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

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

the class RangeSelectorCustomDateParser method getChart.

@Override
protected Component getChart() {
    final Chart chart = new Chart();
    chart.setHeight("450px");
    chart.setWidth("100%");
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    YAxis yAxis = new YAxis();
    PlotLine plotLine = new PlotLine();
    plotLine.setValue(2);
    plotLine.setWidth(2);
    plotLine.setColor(SolidColor.SILVER);
    yAxis.setPlotLines(plotLine);
    configuration.addyAxis(yAxis);
    DataSeries aaplSeries = new DataSeries();
    for (StockPrices.PriceData data : StockPrices.fetchAaplPriceWithTime()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    configuration.setSeries(aaplSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(4);
    ButtonTheme theme = new ButtonTheme();
    Style style = new Style();
    style.setColor(new SolidColor("#0766d8"));
    style.setFontWeight(FontWeight.BOLD);
    theme.setStyle(style);
    rangeSelector.setButtonTheme(theme);
    Style inputStyle = new Style();
    inputStyle.setColor(new SolidColor("#0766d8"));
    inputStyle.setFontWeight(FontWeight.BOLD);
    rangeSelector.setInputStyle(inputStyle);
    rangeSelector.setInputDateFormat("%H:%M:%S.%L");
    rangeSelector.setInputEditDateFormat("%H:%M:%S.%L");
    // All the data is for 2009 Jan 28, so we don't bother to parse date only parse time
    rangeSelector.setInputDateParser("function(value) {" + "value = value.split(/[:\\.]/);\n" + "return Date.UTC(\n" + "   2009,\n" + "   0,\n" + "   28,\n" + "   parseInt(value[0], 10),\n" + "   parseInt(value[1], 10),\n" + "   parseInt(value[2], 10),\n" + "   parseInt(value[3], 10)" + ");}");
    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) Style(com.vaadin.addon.charts.model.style.Style) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) PlotLine(com.vaadin.addon.charts.model.PlotLine) DataSeries(com.vaadin.addon.charts.model.DataSeries) ButtonTheme(com.vaadin.addon.charts.model.style.ButtonTheme) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 4 with RangeSelector

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

use of com.vaadin.addon.charts.model.RangeSelector 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)9 Configuration (com.vaadin.addon.charts.model.Configuration)9 RangeSelector (com.vaadin.addon.charts.model.RangeSelector)9 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)7 DataSeries (com.vaadin.addon.charts.model.DataSeries)7 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)5 DataGrouping (com.vaadin.addon.charts.model.DataGrouping)3 PlotLine (com.vaadin.addon.charts.model.PlotLine)3 TimeUnitMultiples (com.vaadin.addon.charts.model.TimeUnitMultiples)3 YAxis (com.vaadin.addon.charts.model.YAxis)3 OhlcItem (com.vaadin.addon.charts.model.OhlcItem)2 ButtonTheme (com.vaadin.addon.charts.model.style.ButtonTheme)2 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)2 Style (com.vaadin.addon.charts.model.style.Style)2 FlagItem (com.vaadin.addon.charts.model.FlagItem)1 Labels (com.vaadin.addon.charts.model.Labels)1 PlotOptionsCandlestick (com.vaadin.addon.charts.model.PlotOptionsCandlestick)1 PlotOptionsFlags (com.vaadin.addon.charts.model.PlotOptionsFlags)1 PlotOptionsOhlc (com.vaadin.addon.charts.model.PlotOptionsOhlc)1 PlotOptionsSeries (com.vaadin.addon.charts.model.PlotOptionsSeries)1