use of com.vaadin.addon.charts.model.Series in project charts by vaadin.
the class ColumnWithNativeLazyDrilldownMultipleSeries method getChart.
@Override
protected Component getChart() {
final Chart chart = new Chart(ChartType.COLUMN);
chart.setId("chart");
conf = chart.getConfiguration();
conf.setTitle("Browser market share, April, 2011");
conf.setSubTitle("Click the columns to view versions. Click again to view brands.");
conf.getLegend().setEnabled(false);
XAxis x = new XAxis();
x.setType(AxisType.CATEGORY);
conf.addxAxis(x);
YAxis y = new YAxis();
y.setTitle("Total percent market share");
conf.addyAxis(y);
PlotOptionsColumn column = new PlotOptionsColumn();
column.setCursor(Cursor.POINTER);
column.setDataLabels(new DataLabels(true));
column.getDataLabels().setFormatter("this.y +'%'");
conf.setPlotOptions(column);
Tooltip tooltip = new Tooltip();
tooltip.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
tooltip.setPointFormat("<span style=\"color:{point.color}\">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>");
conf.setTooltip(tooltip);
createSeries(1);
createSeries(2);
drillSeries = new HashMap<String, DataSeries>();
addDrillSeries(1);
addDrillSeries(2);
chart.setDrilldownCallback(new DrilldownCallback() {
@Override
public Series handleDrilldown(DrilldownEvent event) {
return getPointDrilldown(event.getItem());
}
});
return chart;
}
use of com.vaadin.addon.charts.model.Series in project charts by vaadin.
the class BasicBarNoTitle method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.BAR);
Configuration conf = chart.getConfiguration();
conf.getTitle().setText(null);
XAxis x = new XAxis();
x.setCategories("Africa", "America", "Asia", "Europe", "Oceania");
x.setTitle((String) null);
conf.addxAxis(x);
YAxis y = new YAxis();
y.setMin(0);
AxisTitle title = new AxisTitle("Population (millions)");
title.setAlign(VerticalAlign.MIDDLE);
y.setTitle(title);
conf.addyAxis(y);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.series.name +': '+ this.y +' millions'");
conf.setTooltip(tooltip);
PlotOptionsBar plot = new PlotOptionsBar();
plot.setDataLabels(new DataLabels(true));
conf.setPlotOptions(plot);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-100);
legend.setY(100);
legend.setFloating(true);
legend.setBorderWidth(1);
legend.setBackgroundColor(new SolidColor("#FFFFFF"));
legend.setShadow(true);
conf.setLegend(legend);
conf.disableCredits();
List<Series> series = new ArrayList<Series>();
series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
conf.setSeries(series);
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.Series in project charts by vaadin.
the class ColumnWithLazyMultiLevelDrilldown method getChart.
@Override
protected Component getChart() {
VerticalLayout layout = new VerticalLayout();
final Chart chart = new Chart(ChartType.COLUMN);
chart.setId("chart");
conf = chart.getConfiguration();
conf.setTitle("Global happiness index");
conf.setSubTitle("Source: www.happyplanetindex.org");
conf.getLegend().setEnabled(false);
XAxis x = new XAxis();
x.setType(AxisType.CATEGORY);
conf.addxAxis(x);
YAxis y = new YAxis();
y.setTitle("Total");
conf.addyAxis(y);
PlotOptionsColumn column = new PlotOptionsColumn();
column.setCursor(Cursor.POINTER);
column.setDataLabels(new DataLabels(true));
conf.setPlotOptions(column);
DataSeries series = new DataSeries();
series.setName("Regions");
PlotOptionsColumn plotOptionsColumn = new PlotOptionsColumn();
plotOptionsColumn.setColorByPoint(true);
series.setPlotOptions(plotOptionsColumn);
DataSeriesItem item = new DataSeriesItem("Latin America and Carribean", 60);
item.setId("Latin America and Carribean");
series.addItemWithDrilldown(item);
item = new DataSeriesItem("Western Nations", 50);
item.setId("Western Nations");
series.addItemWithDrilldown(item);
conf.addSeries(series);
drillSeries = new HashMap<String, DataSeries>();
DataSeries drill = new DataSeries("Latin America and Carribean Countries");
item = new DataSeriesItem("Costa Rica", 64);
item.setId("Costa Rica");
drill.addItemWithDrilldown(item);
item = new DataSeriesItem("Colombia", 59.8);
item.setId("Colombia");
drill.addItemWithDrilldown(item);
item = new DataSeriesItem("Belize", 59.3);
item.setId("Belize");
drill.addItemWithDrilldown(item);
drillSeries.put("Latin America and Carribean", drill);
drill = new DataSeries("Western Nations Countries");
item = new DataSeriesItem("New Zealand", 51.6);
item.setId("New Zealand");
drill.addItemWithDrilldown(item);
item = new DataSeriesItem("Norway", 51.4);
item.setId("Norway");
drill.addItemWithDrilldown(item);
item = new DataSeriesItem("Switzerland", 50.3);
item.setId("Switzerland");
drill.addItemWithDrilldown(item);
drillSeries.put("Western Nations", drill);
drill = new DataSeries("Details Costa Rica");
drill.setId("Details Costa Rica");
String[] categories = new String[] { "Life Expectancy", "Well-being (0-10)", "Footprint (gha/capita)" };
Number[] ys = new Number[] { 79.3, 7.3, 2.5 };
drill.setData(categories, ys);
drillSeries.put("Costa Rica", drill);
drill = new DataSeries("Details Colombia");
drill.setId("Details Colombia");
ys = new Number[] { 73.7, 6.4, 1.8 };
drill.setData(categories, ys);
drillSeries.put("Colombia", drill);
drill = new DataSeries("Details Belize");
drill.setId("Details Belize");
ys = new Number[] { 76.1, 6.5, 2.1 };
drill.setData(categories, ys);
drillSeries.put("Belize", drill);
drill = new DataSeries("Details New Zealand");
drill.setId("Details New Zealand");
ys = new Number[] { 80.7, 7.2, 4.3 };
drill.setData(categories, ys);
drillSeries.put("New Zealand", drill);
drill = new DataSeries("Details Norway");
drill.setId("Details Norway");
ys = new Number[] { 81.1, 7.6, 4.8 };
drill.setData(categories, ys);
drillSeries.put("Norway", drill);
drill = new DataSeries("Details Switzerland");
drill.setId("Details Switzerland");
ys = new Number[] { 82.3, 7.5, 5.0 };
drill.setData(categories, ys);
drillSeries.put("Switzerland", drill);
chart.setDrilldownCallback(new DrilldownCallback() {
@Override
public Series handleDrilldown(DrilldownEvent event) {
log("DrilldownEvent: " + event.getItem().getId());
return getPointDrilldown(event.getItem());
}
});
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
log("PointClickEvent: " + event.getSeries().getName() + " index :" + event.getPointIndex());
}
});
chart.addChartDrillupListener(new ChartDrillupListener() {
@Override
public void onDrillup(ChartDrillupEvent event) {
log("ChartDrillupEvent");
}
});
layout.addComponent(chart);
layout.addComponent(log);
return layout;
}
use of com.vaadin.addon.charts.model.Series in project charts by vaadin.
the class StackedArea method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.AREA);
Configuration conf = chart.getConfiguration();
conf.setTitle(new Title("Historic and Estimated Worldwide Population Growth by Region"));
conf.setSubTitle(new Subtitle("Source: Wikipedia.org"));
XAxis xAxis = new XAxis();
xAxis.setTickmarkPlacement(TickmarkPlacement.ON);
xAxis.setCategories("1750", "1800", "1850", "1900", "1950", "1999", "2050");
conf.addxAxis(xAxis);
YAxis yAxis = new YAxis();
yAxis.setTitle(new AxisTitle("Billions"));
Labels labels = new Labels();
labels.setFormatter("this.value / 1000");
yAxis.setLabels(labels);
conf.addyAxis(yAxis);
Tooltip tooltip = new Tooltip();
tooltip.setFormatter("this.x +': '+ Highcharts.numberFormat(this.y, 0, ',') +' millions'");
conf.setTooltip(tooltip);
PlotOptionsArea plotOptions = new PlotOptionsArea();
plotOptions.setStacking(Stacking.NORMAL);
conf.setPlotOptions(plotOptions);
List<Series> series = new ArrayList<Series>();
series.add(new ListSeries("Asia", 502, 635, 809, 947, 1402, 3634, 5268));
series.add(new ListSeries("Africa", 106, 107, 111, 133, 221, 767, 1766));
series.add(new ListSeries("Europe", 163, 203, 276, 408, 547, 729, 628));
series.add(new ListSeries("America", 18, 31, 54, 156, 339, 818, 1201));
series.add(new ListSeries("Ocenia", 2, 2, 2, 6, 13, 30, 46));
conf.setSeries(series);
chart.drawChart(conf);
return chart;
}
use of com.vaadin.addon.charts.model.Series in project charts by vaadin.
the class ToggledSeriesVisibility method setup.
@Override
protected void setup() {
super.setup();
setSpacing(false);
checkBoxGroup = new CheckBoxGroup<>();
checkBoxGroup.setId("vaadin-optiongroup");
final List<Series> series = chart.getConfiguration().getSeries();
checkBoxGroup.setItems(series);
checkBoxGroup.setItemCaptionGenerator(Series::getName);
for (Series s : series) {
checkBoxGroup.select(s);
}
addComponentAsFirst(checkBoxGroup);
checkBoxGroup.addSelectionListener(e -> {
for (Series s : series) {
((ListSeries) s).setVisible((checkBoxGroup.getSelectedItems()).contains(s));
}
});
}
Aggregations