use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class PyramidChartExample method getChart.
@Override
protected Component getChart() {
DataSeries dataSeries = new DataSeries("Unique users");
dataSeries.add(new DataSeriesItem("Website visits", 15654));
dataSeries.add(new DataSeriesItem("Downloads", 4064));
dataSeries.add(new DataSeriesItem("Requested price list", 1987));
dataSeries.add(new DataSeriesItem("Invoice sent", 976));
dataSeries.add(new DataSeriesItem("Finalized", 846));
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
conf.setTitle("Sales pyramid");
conf.getLegend().setEnabled(false);
PlotOptionsPyramid options = new PlotOptionsPyramid();
// With default (90%), long labels in this example may be cut
options.setWidth(70, Unit.PERCENTAGE);
// in pixels
// options.setWidth(400);
DataLabelsFunnel dataLabels = new DataLabelsFunnel();
dataLabels.setFormat("<b>{point.name}</b> ({point.y:,.0f})");
options.setDataLabels(dataLabels);
dataSeries.setPlotOptions(options);
conf.addSeries(dataSeries);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class DateAxisAndClickEvent method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.setTitle("Date axis and click events");
configuration.getChart().setType(ChartType.SPLINE);
configuration.getxAxis().setType(AxisType.DATETIME);
Calendar c = Calendar.getInstance();
c.set(Calendar.MILLISECOND, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.HOUR_OF_DAY, 12);
c.set(2013, 2, 11);
DataSeries dataSeries = new DataSeries();
Number[] values = new Number[] { 71.5, 29.9, 106.4 };
Random r = new Random(0);
for (Number number : values) {
c.add(Calendar.MINUTE, r.nextInt(5));
DataSeriesItem item = new DataSeriesItem(c.getTime(), number);
dataSeries.add(item);
}
configuration.addSeries(dataSeries);
chart.drawChart(configuration);
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
/*
* The axis value is in client side library's raw format: unix
* timestamp, "shifted" to UTC time zone
*/
;
double timeStampShiftedToUc = event.getxAxisValue();
/*
* When working with Date objects, developers probably want to
* convert it to Date object at their local time zone.
*/
Notification.show("Clicked @ " + Util.toServerInstant(timeStampShiftedToUc));
}
});
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
/*
* Same with point clicks...
*/
;
double timeStampShiftedToUc = event.getX();
Notification.show("Clicked Point with Date value " + Util.toServerInstant(timeStampShiftedToUc));
}
});
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class LineWithMissingPoint method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setHeight("450px");
chart.setWidth("100%");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.LINE);
configuration.getChart().setMarginRight(130);
configuration.getChart().setMarginBottom(25);
configuration.getTitle().setText("Monthly Average Temperature");
configuration.getSubTitle().setText("Source: WorldClimate.com");
configuration.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis yAxis = configuration.getyAxis();
yAxis.setMin(-5d);
yAxis.setTitle(new AxisTitle("Temperature (°C)"));
yAxis.getTitle().setAlign(VerticalAlign.HIGH);
configuration.getTooltip().setFormatter("'<b>'+ this.series.name +'</b><br/>'+this.x +': '+ this.y +'°C'");
PlotOptionsLine plotOptions = new PlotOptionsLine();
plotOptions.setDataLabels(new DataLabels(true));
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-10d);
legend.setY(100d);
legend.setBorderWidth(0);
DataSeries ds = new DataSeries();
DataSeriesItem item = new DataSeriesItem(1, 2);
item.setName("a");
ds.add(item);
item = new DataSeriesItem(2, 2);
item.setName("b");
ds.add(item);
item = new DataSeriesItem(3, 2);
item.setName("c");
ds.add(item);
item = new DataSeriesItem(4, null);
item.setName("d");
ds.add(item);
item = new DataSeriesItem(5, 2);
item.setName("e");
ds.add(item);
item = new DataSeriesItem(6, 2);
item.setName("f");
ds.add(item);
configuration.addSeries(ds);
chart.drawChart(configuration);
System.out.println(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class BoxPlotExample method getChart.
@Override
protected Component getChart() {
chart = new Chart();
chart.getConfiguration().setTitle("Box Plot Example");
Legend legend = new Legend();
legend.setEnabled(false);
chart.getConfiguration().setLegend(legend);
XAxis xaxis = chart.getConfiguration().getxAxis();
xaxis.setTitle("Experiment No.");
xaxis.setCategories("1", "2", "3", "4", "5");
YAxis yAxis = chart.getConfiguration().getyAxis();
yAxis.setTitle("Observations");
PlotLine plotLine = new PlotLine();
plotLine.setColor(new SolidColor("red"));
plotLine.setValue(932);
plotLine.setWidth(1);
plotLine.setZIndex(0);
plotLine.setDashStyle(DashStyle.DASHDOT);
Label label = new Label("Theoretical mean: 932");
label.setAlign(HorizontalAlign.CENTER);
Style style = new Style();
style.setColor(new SolidColor("gray"));
label.setStyle(style);
plotLine.setLabel(label);
PlotLine plotLine2 = new PlotLine();
plotLine2.setColor(new SolidColor("blue"));
plotLine2.setValue(800);
plotLine2.setWidth(1);
plotLine2.setZIndex(500);
plotLine2.setDashStyle(DashStyle.SHORTDASHDOTDOT);
Label label2 = new Label("Second plotline: 800");
label2.setAlign(HorizontalAlign.CENTER);
Style style2 = new Style();
style2.setColor(new SolidColor("gray"));
label2.setStyle(style2);
plotLine2.setLabel(label2);
yAxis.setPlotLines(plotLine, plotLine2);
observations = new DataSeries();
observations.setName("Observations");
// Add PlotBoxItems contain all fields relevant for plot box chart
observations.add(new BoxPlotItem(760, 801, 848, 895, 965));
// Example with no arg constructor
BoxPlotItem plotBoxItem = new BoxPlotItem();
plotBoxItem.setLow(733);
plotBoxItem.setLowerQuartile(853);
plotBoxItem.setMedian(939);
plotBoxItem.setUpperQuartile(980);
plotBoxItem.setHigh(1080);
observations.add(plotBoxItem);
observations.add(new BoxPlotItem(714, 762, 817, 870, 918));
observations.add(new BoxPlotItem(724, 802, 806, 871, 950));
observations.add(new BoxPlotItem(834, 836, 864, 882, 910));
observations.setPlotOptions(getPlotBoxOptions());
chart.getConfiguration().addSeries(observations);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class BubbleChartExample method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart(ChartType.BUBBLE);
Configuration conf = chart.getConfiguration();
conf.setTitle((String) null);
DataSeries dataSeries = new DataSeries();
dataSeries.add(item(9, 81, 13));
dataSeries.add(item(98, 5, 39));
dataSeries.add(item(51, 50, 23));
dataSeries.add(item(41, 22, -36));
dataSeries.add(item(58, 24, -30));
dataSeries.add(item(78, 37, -16));
dataSeries.add(item(55, 56, 3));
dataSeries.add(item(18, 45, 20));
dataSeries.add(item(42, 44, -22));
dataSeries.add(item(3, 52, 9));
dataSeries.add(item(31, 18, 47));
dataSeries.add(item(79, 91, 13));
dataSeries.add(item(93, 23, -27));
dataSeries.add(item(44, 83, -28));
PlotOptionsBubble opts = new PlotOptionsBubble();
opts.setNegativeColor(getThemeColors()[3]);
opts.setMaxSize("120");
opts.setMinSize("3");
conf.setPlotOptions(opts);
conf.addSeries(dataSeries);
DataSeries dataSeries2 = new DataSeries("Negative bubbles hidden");
dataSeries2.add(item(13, 30, 10));
dataSeries2.add(item(23, 20, -10));
dataSeries2.add(item(23, 40, 10));
opts = new PlotOptionsBubble();
opts.setDisplayNegative(false);
dataSeries2.setPlotOptions(opts);
conf.addSeries(dataSeries2);
return chart;
}
Aggregations