use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class CompareMultipleSeries method initDemo.
@Override
public void initDemo() {
final Chart chart = new Chart();
chart.setTimeline(true);
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("AAPL Stock Price");
YAxis yAxis = new YAxis();
Labels label = new Labels();
label.setFormatter("function() { return (this.value > 0 ? ' + ' : '') + this.value + '%'; }");
yAxis.setLabels(label);
PlotLine plotLine = new PlotLine();
plotLine.setValue(2);
plotLine.setWidth(2);
yAxis.setPlotLines(plotLine);
configuration.addyAxis(yAxis);
Tooltip tooltip = new Tooltip();
tooltip.setPointFormat("<span>{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(Compare.PERCENT);
configuration.setPlotOptions(plotOptionsSeries);
RangeSelector rangeSelector = new RangeSelector();
rangeSelector.setSelected(4);
configuration.setRangeSelector(rangeSelector);
add(chart);
}
use of com.vaadin.flow.component.charts.Chart in project flow-components by vaadin.
the class Spline method initDemo.
@Override
public void initDemo() {
Chart chart = new Chart(ChartType.SPLINE);
chart.setTimeline(true);
Configuration configuration = chart.getConfiguration();
configuration.getTitle().setText("AAPL Stock Price");
configuration.getTooltip().setEnabled(true);
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.addSeries(dataSeries);
RangeSelector rangeSelector = new RangeSelector();
rangeSelector.setSelected(1);
configuration.setRangeSelector(rangeSelector);
add(chart);
}
Aggregations