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