Search in sources :

Example 1 with PlotOptionsErrorbar

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;
}
Also used : PlotOptionsErrorbar(com.vaadin.addon.charts.model.PlotOptionsErrorbar) Configuration(com.vaadin.addon.charts.model.Configuration) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Color(com.vaadin.addon.charts.model.style.Color) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Labels(com.vaadin.addon.charts.model.Labels) PlotOptionsSpline(com.vaadin.addon.charts.model.PlotOptionsSpline) PlotOptionsColumn(com.vaadin.addon.charts.model.PlotOptionsColumn) Style(com.vaadin.addon.charts.model.style.Style) DataSeries(com.vaadin.addon.charts.model.DataSeries) AxisTitle(com.vaadin.addon.charts.model.AxisTitle) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem) YAxis(com.vaadin.addon.charts.model.YAxis) SeriesTooltip(com.vaadin.addon.charts.model.SeriesTooltip)

Example 2 with PlotOptionsErrorbar

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);
}
Also used : PlotOptionsErrorbar(com.vaadin.addon.charts.model.PlotOptionsErrorbar) Configuration(com.vaadin.addon.charts.model.Configuration) ListSeries(com.vaadin.addon.charts.model.ListSeries) DataSeries(com.vaadin.addon.charts.model.DataSeries) Chart(com.vaadin.addon.charts.Chart) DataSeriesItem(com.vaadin.addon.charts.model.DataSeriesItem)

Aggregations

Chart (com.vaadin.addon.charts.Chart)2 Configuration (com.vaadin.addon.charts.model.Configuration)2 DataSeries (com.vaadin.addon.charts.model.DataSeries)2 DataSeriesItem (com.vaadin.addon.charts.model.DataSeriesItem)2 PlotOptionsErrorbar (com.vaadin.addon.charts.model.PlotOptionsErrorbar)2 AxisTitle (com.vaadin.addon.charts.model.AxisTitle)1 Labels (com.vaadin.addon.charts.model.Labels)1 ListSeries (com.vaadin.addon.charts.model.ListSeries)1 PlotOptionsColumn (com.vaadin.addon.charts.model.PlotOptionsColumn)1 PlotOptionsSpline (com.vaadin.addon.charts.model.PlotOptionsSpline)1 SeriesTooltip (com.vaadin.addon.charts.model.SeriesTooltip)1 YAxis (com.vaadin.addon.charts.model.YAxis)1 Color (com.vaadin.addon.charts.model.style.Color)1 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)1 Style (com.vaadin.addon.charts.model.style.Style)1