use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class ContainerSeriesJSONSerializationTest method serialize_ContainerWithSeriesPlotOptions_PlotTypeNotSerialized.
@Test
public void serialize_ContainerWithSeriesPlotOptions_PlotTypeNotSerialized() {
PlotOptionsSeries plotOptions = new PlotOptionsSeries();
plotOptions.setShowInLegend(true);
containerSeries.setPlotOptions(plotOptions);
Configuration config = new Configuration();
config.addSeries(containerSeries);
assertEquals("{\"showInLegend\":true,\"data\":[]}", toJSON(containerSeries));
}
use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class ClickToAddPoint method getChart.
@Override
protected Component getChart() {
lastAction.setId("lastAction");
eventDetails.setId("eventDetails");
chart = new Chart();
chart.setId("chart");
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SCATTER);
configuration.getTitle().setText("User supplied data");
configuration.getSubTitle().setText("Click the plot area to add a point. Click a point to remove it.");
XAxis xAxis = configuration.getxAxis();
xAxis.setMinPadding(0.2);
xAxis.setMaxPadding(0.2);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
yAxis.setMinPadding(0.2);
yAxis.setMaxPadding(0.2);
Legend legend = configuration.getLegend();
legend.setEnabled(false);
configuration.setExporting(false);
PlotOptionsSeries opt = new PlotOptionsSeries();
opt.setLineWidth(1);
configuration.setPlotOptions(opt);
final DataSeries series = new DataSeries();
series.add(new DataSeriesItem(20, 20));
series.add(new DataSeriesItem(80, 80));
configuration.setSeries(series);
chart.drawChart(configuration);
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
double x = Math.round(event.getxAxisValue());
double y = Math.round(event.getyAxisValue());
series.add(new DataSeriesItem(x, y));
lastAction.setValue("Added point " + x + "," + y);
eventDetails.setValue(createEventString(event));
}
});
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
DataSeries ds = (DataSeries) event.getSeries();
DataSeriesItem dataSeriesItem2 = ds.get(event.getPointIndex());
ds.remove(dataSeriesItem2);
lastAction.setValue("Removed point at index " + event.getPointIndex());
eventDetails.setValue(createEventString(event));
}
});
VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.setSpacing(false);
verticalLayout.setMargin(false);
verticalLayout.addComponent(chart);
verticalLayout.addComponent(lastAction);
verticalLayout.addComponent(eventDetails);
return verticalLayout;
}
use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class BarWithNegativeStack method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.BAR);
Configuration conf = chart.getConfiguration();
conf.setTitle("Population pyramid for Germany, midyear 2010");
conf.setSubTitle("Source: www.census.gov");
final String[] categories = new String[] { "0-4", "5-9", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54", "55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90-94", "95-99", "100 +" };
XAxis x1 = new XAxis();
conf.addxAxis(x1);
x1.setCategories(categories);
x1.setReversed(false);
XAxis x2 = new XAxis();
conf.addxAxis(x2);
x2.setCategories(categories);
x2.setOpposite(true);
x2.setReversed(false);
x2.setLinkedTo(x1);
YAxis y = new YAxis();
y.setMin(-4000000);
y.setMax(4000000);
y.setTitle(new AxisTitle(""));
conf.addyAxis(y);
PlotOptionsSeries plot = new PlotOptionsSeries();
plot.setStacking(Stacking.NORMAL);
conf.setPlotOptions(plot);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("'<b>'+ this.series.name +', age '+ this.point.category +'</b><br/>'+ 'Population: '+ Highcharts.numberFormat(Math.abs(this.point.y), 0)");
conf.setTooltip(tooltip);
conf.addSeries(new ListSeries("Male", -1746181, -1884428, -2089758, -2222362, -2537431, -2507081, -2443179, -2664537, -3556505, -3680231, -3143062, -2721122, -2229181, -2227768, -2176300, -1329968, -836804, -354784, -90569, -28367, -3878));
conf.addSeries(new ListSeries("Female", 1656154, 1787564, 1981671, 2108575, 2403438, 2366003, 2301402, 2519874, 3360596, 3493473, 3050775, 2759560, 2304444, 2426504, 2568938, 1785638, 1447162, 1005011, 330870, 130632, 21208));
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class ServerSideEvents method getChart.
@Override
protected Component getChart() {
eventDetails.setId("eventDetails");
lastEvent.setId("lastEvent");
historyLayout.setId("history");
chart = new Chart();
chart.setId("chart");
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SCATTER);
configuration.getTitle().setText("Test server side events.");
configuration.getSubTitle().setText("When an event occurs, the details are shown below the chart");
configuration.setExporting(true);
configuration.getChart().setAnimation(false);
configuration.getChart().setZoomType(ZoomType.XY);
XAxis xAxis = configuration.getxAxis();
xAxis.setMinPadding(0.2);
xAxis.setMaxPadding(0.2);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
PlotLine plotline = new PlotLine();
plotline.setValue(0);
plotline.setWidth(1);
plotline.setColor(new SolidColor("#808080"));
yAxis.setPlotLines(new PlotLine[] { plotline });
yAxis.setMinPadding(0.2);
yAxis.setMaxPadding(0.2);
YAxis yAxis1 = new YAxis();
yAxis1.setTitle("Another axis");
yAxis1.setOpposite(true);
configuration.addyAxis(yAxis1);
PlotOptionsSeries opt = new PlotOptionsSeries();
opt.setLineWidth(1);
opt.setShowCheckbox(true);
opt.setAllowPointSelect(true);
configuration.setPlotOptions(opt);
configuration.setTooltip(new Tooltip(false));
final DataSeries series1 = createDataSeries(0);
final DataSeries series2 = createDataSeries(20);
DataSeries series3 = createDataSeries(100);
series3.get(0).setY(105);
series3.get(3).setY(95);
series3.setName("Another axis");
series3.setyAxis(1);
firstDataPoint = series1.get(0);
firstDataPoint.setSelected(true);
configuration.setSeries(series1, series2, series3);
chart.drawChart(configuration);
final Layout toggles = createControls();
Layout eventListeners = addEventListeners();
chart.setSeriesVisibilityTogglingDisabled(false);
visibilityToggling.setValue(false);
lastEvent.setCaption("Last event");
eventDetails.setCaption("Details");
historyLayout.setCaption("History");
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.addComponent(toggles);
HorizontalLayout chartAndListeners = new HorizontalLayout(chart, eventListeners);
chartAndListeners.setSizeUndefined();
chartAndListeners.setSpacing(true);
layout.addComponent(chartAndListeners);
layout.addComponent(lastEvent);
layout.addComponent(eventDetails);
layout.addComponent(historyLayout);
return layout;
}
use of com.vaadin.addon.charts.model.PlotOptionsSeries in project charts by vaadin.
the class PolarChart method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.getChart().setPolar(true);
conf.setTitle("Polar Chart");
Pane pane = new Pane(0, 360);
conf.addPane(pane);
pane.setBackground(new Background[] {});
XAxis axis = new XAxis();
axis.setTickInterval(45);
axis.setMin(0);
axis.setMax(360);
Labels labels = new Labels();
labels.setFormatter("function() {return this.value + '°';}");
axis.setLabels(labels);
YAxis yaxs = new YAxis();
yaxs.setMin(0);
conf.addxAxis(axis);
conf.addyAxis(yaxs);
PlotOptionsSeries series = new PlotOptionsSeries();
PlotOptionsColumn column = new PlotOptionsColumn();
series.setPointStart(0);
series.setPointInterval(45);
column.setPointPadding(0);
column.setGroupPadding(0);
conf.setPlotOptions(series, column);
ListSeries col = new ListSeries(8, 7, 6, 5, 4, 3, 2, 1);
ListSeries line = new ListSeries(1, 2, 3, 4, 5, 6, 7, 8);
ListSeries area = new ListSeries(1, 8, 2, 7, 3, 6, 4, 5);
col.setPlotOptions(new PlotOptionsColumn());
col.setName(ChartType.COLUMN.toString());
line.setPlotOptions(new PlotOptionsLine());
line.setName(ChartType.LINE.toString());
area.setPlotOptions(new PlotOptionsArea());
area.setName(ChartType.AREA.toString());
conf.setSeries(col, line, area);
chart.drawChart(conf);
return chart;
}
Aggregations