Search in sources :

Example 6 with RangeSelector

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

the class RangeSelectorButtons 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.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        aaplSeries.add(item);
    }
    configuration.setSeries(aaplSeries);
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setSelected(1);
    RangeSelectorButton button = new RangeSelectorButton(MONTH, 3, "D");
    DataGrouping grouping = new DataGrouping();
    grouping.setForced(true);
    grouping.setUnits(new TimeUnitMultiples(TimeUnit.DAY, 1));
    button.setDataGrouping(grouping);
    rangeSelector.addButton(button);
    button = new RangeSelectorButton(YEAR, 1, "W");
    grouping = new DataGrouping();
    grouping.setForced(true);
    grouping.setUnits(new TimeUnitMultiples(TimeUnit.WEEK, 1));
    button.setDataGrouping(grouping);
    rangeSelector.addButton(button);
    button = new RangeSelectorButton(ALL, "M");
    grouping = new DataGrouping();
    grouping.setForced(true);
    grouping.setUnits(new TimeUnitMultiples(TimeUnit.MONTH, 1));
    button.setDataGrouping(grouping);
    rangeSelector.addButton(button);
    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) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) DataGrouping(com.vaadin.addon.charts.model.DataGrouping) RangeSelectorButton(com.vaadin.addon.charts.model.RangeSelectorButton) 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) YAxis(com.vaadin.addon.charts.model.YAxis)

Example 7 with RangeSelector

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

the class SingleLineSeries 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();
    for (StockPrices.PriceData data : StockPrices.fetchAaplPrice()) {
        DataSeriesItem item = new DataSeriesItem();
        item.setX(data.getDate());
        item.setY(data.getPrice());
        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) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Example 8 with RangeSelector

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

the class Timeline method chartsTimelineIntroSnippet3.

public void chartsTimelineIntroSnippet3() {
    Chart chart = new Chart();
    Configuration configuration = chart.getConfiguration();
    RangeSelector rangeSelector = new RangeSelector();
    rangeSelector.setInputDateFormat("%YYYY-%MM-%DD:%H:%M");
    rangeSelector.setInputEditDateFormat("%YYYY-%MM-%DD:%H:%M");
    rangeSelector.setInputDateParser("function(value) {" + "value = value.split(/[:\\-]/);\n" + "return Date.UTC(\n" + "   parseInt(value[0], 10),\n" + "   parseInt(value[1], 10),\n" + "   parseInt(value[2], 10),\n" + "   parseInt(value[3], 10),\n" + "   parseInt(value[4], 10),\n" + ");}");
    configuration.setRangeSelector(rangeSelector);
}
Also used : Configuration(com.vaadin.addon.charts.model.Configuration) RangeSelector(com.vaadin.addon.charts.model.RangeSelector) Chart(com.vaadin.addon.charts.Chart)

Example 9 with RangeSelector

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

the class Timeline method chartsTimelineIntroSnippet2.

public void chartsTimelineIntroSnippet2() {
    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);
    Chart chart = new Chart();
    chart.setTimeline(true);
    Configuration configuration = chart.getConfiguration();
    configuration.setRangeSelector(rangeSelector);
}
Also used : 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) ButtonTheme(com.vaadin.addon.charts.model.style.ButtonTheme) 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