use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class BasicLineGettingMousePointerPosition method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setId("chart");
Color[] colors = getThemeColors();
Configuration conf = chart.getConfiguration();
conf.getChart().setZoomType(ZoomType.XY);
conf.setTitle("Average Monthly Temperature and Rainfall in Tokyo");
conf.setSubTitle("Source: WorldClimate.com");
XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
conf.addxAxis(x);
YAxis primary = new YAxis();
primary.setTitle("Temperature");
Style style = new Style();
style.setColor(colors[0]);
primary.getTitle().setStyle(style);
conf.addyAxis(primary);
YAxis snd = new YAxis();
snd.setTitle("Rainfall");
snd.setOpposite(true);
style = new Style();
style.setColor(colors[1]);
snd.getTitle().setStyle(style);
conf.addyAxis(snd);
Tooltip tooltip = new Tooltip(false);
conf.setTooltip(tooltip);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setAlign(HorizontalAlign.LEFT);
legend.setX(120);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setY(100);
legend.setFloating(true);
legend.setBackgroundColor(new SolidColor("#FFFFFF"));
conf.setLegend(legend);
DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsColumn());
series.setName("Rainfall");
series.setData(49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
series.setyAxis(1);
conf.addSeries(series);
series = new DataSeries();
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
series.setPlotOptions(plotOptions);
series.setName("Temperature");
series.setData(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6);
conf.addSeries(series);
chart.addPointClickListener(new PointClickListener() {
@Override
public void onClick(PointClickEvent event) {
Window win = new Window("PointClickEvent window");
win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
win.setPositionX(event.getAbsoluteX());
win.setPositionY(event.getAbsoluteY());
getUI().addWindow(win);
}
});
chart.addChartClickListener(new ChartClickListener() {
@Override
public void onClick(ChartClickEvent event) {
Window win = new Window("Chart Click Event Window");
win.setContent(new Label("Browser client area coordinates: point X:" + event.getAbsoluteX() + " Y:" + event.getAbsoluteY()));
win.setPositionX(event.getAbsoluteX());
win.setPositionY(event.getAbsoluteY());
getUI().addWindow(win);
}
});
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class SplineInverted method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
chart.setWidth("500px");
Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getChart().setInverted(true);
configuration.getTitle().setText("Atmosphere Temperature by Altitude");
configuration.getSubTitle().setText("According to the Standard Atmosphere Model");
XAxis xAxis = configuration.getxAxis();
xAxis.setReversed(false);
xAxis.setTitle(new AxisTitle("Altitude"));
Labels labels = new Labels();
labels.setFormatter("this.value + 'km'");
labels.setEnabled(true);
xAxis.setLabels(labels);
xAxis.setMaxPadding(0.05);
xAxis.setShowLastLabel(true);
YAxis yAxis = configuration.getyAxis();
yAxis.setLineWidth(2);
yAxis.setTitle(new AxisTitle("Temperature"));
yAxis.getTitle().setAlign(VerticalAlign.MIDDLE);
Labels labelsy = new Labels();
labelsy.setEnabled(true);
labelsy.setFormatter("this.value + '°'");
yAxis.setLabels(labelsy);
configuration.getTooltip().setFormatter("this.x +' km: '+this.y +'°C'");
PlotOptionsSpline plotOptions = new PlotOptionsSpline();
plotOptions.setMarker(new Marker(true));
configuration.setPlotOptions(plotOptions);
Legend legend = configuration.getLegend();
legend.setEnabled(false);
DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Temperature");
series.addData(new Number[][] { { 0, 15 }, { 10, -50 }, { 20, -56.5 }, { 30, -46.5 }, { 40, -22.1 }, { 50, -2.5 }, { 60, -27.7 }, { 70, -55.7 }, { 80, -76.5 } });
configuration.setSeries(series);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class SplineUpdatingEachSecond method getChart.
@Override
protected Component getChart() {
final Random random = new Random();
final Chart chart = new Chart();
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Live random data");
XAxis xAxis = configuration.getxAxis();
xAxis.setType(AxisType.DATETIME);
xAxis.setTickPixelInterval(150);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
configuration.getTooltip().setEnabled(false);
configuration.getLegend().setEnabled(false);
final DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Random data");
for (int i = -19; i <= 0; i++) {
series.add(new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble()));
}
runWhileAttached(chart, new Runnable() {
@Override
public void run() {
final long x = System.currentTimeMillis();
final double y = random.nextDouble();
series.add(new DataSeriesItem(x, y), true, true);
}
}, 1000, 1000);
configuration.setSeries(series);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class SplineUpdatingEachSecondWithCustomizedNewPoints method getChart.
@Override
protected Component getChart() {
final Random random = new Random();
final Chart chart = new Chart();
chart.setWidth("500px");
final Configuration configuration = chart.getConfiguration();
configuration.getChart().setType(ChartType.SPLINE);
configuration.getTitle().setText("Live random data");
XAxis xAxis = configuration.getxAxis();
xAxis.setType(AxisType.DATETIME);
xAxis.setTickPixelInterval(150);
YAxis yAxis = configuration.getyAxis();
yAxis.setTitle(new AxisTitle("Value"));
yAxis.setPlotLines(new PlotLine(0, 1, new SolidColor("#808080")));
configuration.getTooltip().setEnabled(false);
configuration.getLegend().setEnabled(false);
final DataSeries series = new DataSeries();
series.setPlotOptions(new PlotOptionsSpline());
series.setName("Random data");
for (int i = -19; i <= 0; i++) {
DataSeriesItem item = new DataSeriesItem(System.currentTimeMillis() + i * 1000, random.nextDouble());
series.add(item);
}
runWhileAttached(chart, new Runnable() {
@Override
public void run() {
final long x = System.currentTimeMillis();
final double y = random.nextDouble();
DataSeriesItem item = new DataSeriesItem(x, y);
item.setName("Diipaiapa");
Marker marker = new Marker();
marker.setEnabled(true);
boolean b = (new Random().nextInt(5) % 4 == 0);
marker.setFillColor(new SolidColor(b ? "#ff0000" : "#000000"));
item.setMarker(marker);
series.add(item, true, true);
}
}, 1000, 1000);
configuration.setSeries(series);
chart.drawChart(configuration);
return chart;
}
use of com.vaadin.addon.charts.model.DataSeries in project charts by vaadin.
the class FunnelChartExample 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 funnel");
conf.getLegend().setEnabled(false);
PlotOptionsFunnel options = new PlotOptionsFunnel();
options.setReversed(false);
options.setNeckWidth("30%");
options.setNeckHeight("30%");
options.setWidth("70%");
DataLabelsFunnel dataLabels = new DataLabelsFunnel();
dataLabels.setFormat("<b>{point.name}</b> ({point.y:,.0f})");
options.setDataLabels(dataLabels);
dataSeries.setPlotOptions(options);
conf.addSeries(dataSeries);
return chart;
}
Aggregations