use of com.vaadin.addon.charts.model.PlotOptionsSeries 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.PlotOptionsSeries in project charts by vaadin.
the class DataProviderSeriesBeanSerializer method serialize.
@Override
public void serialize(DataProviderSeries bean, BeanSerializerDelegator<DataProviderSeries> serializer, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
if (bean.getPlotOptions() != null && !(bean.getPlotOptions() instanceof PlotOptionsSeries)) {
jgen.writeObjectField("type", bean.getPlotOptions().getChartType());
}
// write other fields as per normal serialization rules
serializer.serializeFields(bean, jgen, provider);
ArrayNode data = createDataArray(bean);
jgen.writeObjectField("data", data);
jgen.writeEndObject();
}
use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class TimeSeriesIntervalUnit method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setSpacingRight(20);
configuration.getTitle().setText("Point interval test");
configuration.getxAxis().setType(AxisType.DATETIME);
final PlotOptionsSeries plotOptions = new PlotOptionsSeries();
try {
DateFormat df = new SimpleDateFormat("yyyyMMdd");
plotOptions.setPointStart(df.parse("20150101"));
} catch (ParseException e) {
e.printStackTrace();
}
plotOptions.setPointInterval(1);
plotOptions.setPointIntervalUnit(IntervalUnit.MONTH);
configuration.setPlotOptions(plotOptions);
ListSeries ls = new ListSeries();
ls.setData(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
configuration.setSeries(ls);
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
layout.addComponent(chart);
layout.addComponent(new Button("one day interval", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
plotOptions.setPointInterval(24 * 3600 * 1000);
plotOptions.setPointIntervalUnit(null);
chart.drawChart();
}
}));
return layout;
}
use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class DataSeriesItemJSONSerializationTest method toJSON_PlotOptionsSeriesIsSet_SeriesSerializedWithoutType.
@Test
public void toJSON_PlotOptionsSeriesIsSet_SeriesSerializedWithoutType() {
DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSeries());
String expected = "{\"data\":[]}";
assertEquals(expected, toJSON(series));
}
use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class StackedBar method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.BAR);
Configuration conf = chart.getConfiguration();
conf.setTitle("Stacked bar chart");
XAxis x = new XAxis();
x.setCategories("Apples", "Oranges", "Pears", "Grapes", "Bananas");
conf.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
y.setTitle("Total fruit consumption");
conf.addyAxis(y);
Legend legend = new Legend();
legend.setBackgroundColor(new SolidColor("#FFFFFF"));
legend.setReversed(true);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.series.name +': '+ this.y");
conf.setTooltip(tooltip);
PlotOptionsSeries plot = new PlotOptionsSeries();
plot.setStacking(Stacking.NORMAL);
conf.setPlotOptions(plot);
conf.addSeries(new ListSeries("John", 5, 3, 4, 7, 2));
conf.addSeries(new ListSeries("Jane", 2, 2, 3, 2, 1));
conf.addSeries(new ListSeries("Joe", 3, 4, 4, 2, 5));
chart.drawChart(conf);
return chart;
}
Aggregations