use of com.vaadin.addon.charts.model.PlotOptionsErrorbar in project charts by vaadin.
the class ErrorBarExample method getChart.
@Override
protected Component getChart() {
Chart chart = new Chart();
Configuration conf = chart.getConfiguration();
Color[] colors = getThemeColors();
// Enable xy zooming, test also with touch devices
conf.getChart().setZoomType(ZoomType.XY);
conf.setTitle("Temperature vs Rainfall");
conf.getxAxis().setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
YAxis primaryAxis = conf.getyAxis();
AxisTitle title = new AxisTitle("Temperature");
Style style = new Style();
style.setColor(colors[0]);
title.setStyle(style);
primaryAxis.setTitle(title);
Labels labels = new Labels();
labels.setFormatter("this.value + '°C'");
primaryAxis.setLabels(labels);
YAxis secondaryAxis = new YAxis();
conf.addyAxis(secondaryAxis);
title = new AxisTitle("Rainfall");
secondaryAxis.setTitle(title);
style = new Style();
style.setColor(colors[1]);
title.setStyle(style);
labels = new Labels();
labels.setFormatter("this.value + ' mm'");
labels.setStyle(style);
secondaryAxis.setLabels(labels);
secondaryAxis.setOpposite(true);
conf.getTooltip().setShared(true);
DataSeries rainfall = new DataSeries("Rainfall");
PlotOptionsColumn column = new PlotOptionsColumn();
column.setColor(colors[1]);
SeriesTooltip tooltip = new SeriesTooltip();
tooltip.setPointFormat("<span style='font-weight: bold; color: {series.color}'>{series.name}</span>: <b>{point.y:.1f} mm</b> ");
column.setTooltip(tooltip);
rainfall.setPlotOptions(column);
conf.addSeries(rainfall);
rainfall.setyAxis(secondaryAxis);
DataSeries rainfallError = new DataSeries("Rainfall");
conf.addSeries(rainfallError);
rainfallError.setyAxis(secondaryAxis);
PlotOptionsErrorbar rainErrorOptions = new PlotOptionsErrorbar();
tooltip = new SeriesTooltip();
tooltip.setPointFormat("(error range: {point.low}-{point.high} mm)<br/>");
rainErrorOptions.setTooltip(tooltip);
rainfallError.setPlotOptions(rainErrorOptions);
DataSeries temperature = new DataSeries("Temperature");
conf.addSeries(temperature);
PlotOptionsSpline tempOptions = new PlotOptionsSpline();
tempOptions.setColor(colors[0]);
tooltip = new SeriesTooltip();
tooltip.setPointFormat("<span style='font-weight: bold; color: {series.color}'>{series.name}</span>: <b>{point.y:.1f}°C");
tempOptions.setTooltip(tooltip);
temperature.setPlotOptions(tempOptions);
DataSeries temperatureErrors = new DataSeries("Temperature error");
conf.addSeries(temperatureErrors);
PlotOptionsErrorbar tempErrorOptions = new PlotOptionsErrorbar();
SolidColor green = new SolidColor("green");
tempErrorOptions.setStemColor(green);
tempErrorOptions.setWhiskerColor(green);
tooltip = new SeriesTooltip();
tooltip.setPointFormat("(error range: {point.low}-{point.high}°C)<br/>");
tempErrorOptions.setTooltip(tooltip);
temperatureErrors.setPlotOptions(tempErrorOptions);
// Populate series
for (Data d : DATA) {
DataSeriesItem item = new DataSeriesItem();
item.setY(d.rainfall);
rainfall.add(item);
item = new DataSeriesItem();
item.setLow(d.rainfallErrorLow);
item.setHigh(d.rainfallErrorHigh);
rainfallError.add(item);
item = new DataSeriesItem();
item.setY(d.temperature);
temperature.add(item);
item = new DataSeriesItem();
item.setLow(d.temperatureErrorLow);
item.setHigh(d.temperatureErrorHigh);
temperatureErrors.add(item);
}
return chart;
}
use of com.vaadin.addon.charts.model.PlotOptionsErrorbar in project charts by vaadin.
the class ChartTypes method chartTypesErrorbarSnippet1.
public void chartTypesErrorbarSnippet1() {
// Create a chart of some primary type
Chart chart = new Chart(ChartType.SCATTER);
chart.setWidth("600px");
chart.setHeight("400px");
// Modify the default configuration a bit
Configuration conf = chart.getConfiguration();
conf.setTitle("Average Temperatures in Turku");
conf.getLegend().setEnabled(false);
// The primary data series
ListSeries averages = new ListSeries(-6, -6.5, -4, 3, 9, 14, 17, 16, 11, 6, 2, -2.5);
// Error bar data series with low and high values
DataSeries errors = new DataSeries();
errors.add(new DataSeriesItem(0, -9, -3));
errors.add(new DataSeriesItem(1, -10, -3));
errors.add(new DataSeriesItem(2, -8, 1));
// Configure the stem and whiskers in error bars
PlotOptionsErrorbar barOptions = new PlotOptionsErrorbar();
barOptions.setStemColor(SolidColor.GREY);
barOptions.setStemWidth(2);
barOptions.setStemDashStyle(DashStyle.DASH);
barOptions.setWhiskerColor(SolidColor.BROWN);
// 80% of category width
barOptions.setWhiskerLength(80, Sizeable.Unit.PERCENTAGE);
// Pixels
barOptions.setWhiskerWidth(2);
errors.setPlotOptions(barOptions);
// The errors should be drawn lower
conf.addSeries(errors);
conf.addSeries(averages);
}
Aggregations