Search in sources :

Example 1 with RangeSelectorButton

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

Aggregations

Chart (com.vaadin.addon.charts.Chart)1 StockPrices (com.vaadin.addon.charts.examples.timeline.util.StockPrices)1 Configuration (com.vaadin.addon.charts.model.Configuration)1 DataGrouping (com.vaadin.addon.charts.model.DataGrouping)1 DataSeries (com.vaadin.addon.charts.model.DataSeries)1 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)1 PlotLine (com.vaadin.addon.charts.model.PlotLine)1 RangeSelector (com.vaadin.addon.charts.model.RangeSelector)1 RangeSelectorButton (com.vaadin.addon.charts.model.RangeSelectorButton)1 TimeUnitMultiples (com.vaadin.addon.charts.model.TimeUnitMultiples)1 YAxis (com.vaadin.addon.charts.model.YAxis)1