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;
}
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;
}
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);
}
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);
}
Aggregations