> Markdown version of [Error Bars](https://vaadin.com/docs/latest/it/components/charts/charttypes/error-bars). Section index: [llms.txt](https://vaadin.com/docs/latest/it/components/llms.txt)

# <a id="charts.charttypes.errorbar"></a>Barre di errore

Le barre di errore visualizzano gli errori, o i valori alti e bassi, nei dati statistici. In genere rappresentano valori alti e bassi nei dati, oppure una deviazione standard, un percentile, o un quantile. I valori alti e bassi sono rappresentati come linee orizzontali, o "whiskers", collegate da uno stelo verticale.

Sebbene le barre di errore siano tecnicamente un tipo di grafico (`ChartType.ERRORBAR`), normalmente le si usa insieme a un tipo di grafico primario, come un grafico a dispersione o a colonne.

[Image: charts errorbar]

Barre di errore in un grafico a dispersione

Per visualizzare le barre di errore per i punti dati, è necessario avere una serie di dati separata per i valori bassi e alti. La serie di dati deve usare il tipo di opzioni di tracciamento `PlotOptionsErrorBar`.

```java
// Create a chart of some primary type
Chart chart = new Chart(ChartType.SCATTER);

// 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));
...

// Need to be used for series to be recognized as error bar
PlotOptionsErrorbar barOptions = new PlotOptionsErrorbar();
errors.setPlotOptions(barOptions);

// The errors should be drawn lower
conf.addSeries(errors);
conf.addSeries(averages);
```

È consigliabile aggiungere prima la serie delle barre di errore, in modo che venga resa più in basso nel grafico.

## <a id="charts.charttypes.errorbar.plotoptions"></a>Opzioni di tracciamento

Le opzioni di tracciamento per i grafici con barre di errore hanno tipo `PlotOptionsErrorBar`. Consultare la documentazione API per i dettagli sulle opzioni di tracciamento.

> **Note:** Sebbene la maggior parte degli [visual styles are defined in CSS](https://vaadin.com/docs/latest/it/components/charts/styling.md#css.styling), alcune opzioni, come `whiskerLength`, vengono impostate tramite la Java API.

## <a id="esempio-di-barre-di-errore"></a>Esempio di barre di errore

**Flow** — `ChartTypeErrorBar.java`

```java
Chart chart = new Chart(ChartType.ERRORBAR);

Configuration configuration = chart.getConfiguration();
configuration.setTitle("Monthly Rainfall");

XAxis x = new XAxis();
x.setCategories("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
        "Sep", "Oct", "Nov", "Dec");
configuration.addxAxis(x);

YAxis y = new YAxis();
Labels yLabels = new Labels();
yLabels.setFormat("{value} mm");
y.setLabels(yLabels);
y.setTitle("Rainfall");
configuration.addyAxis(y);

Tooltip tooltip = new Tooltip();
tooltip.setShared(true);
configuration.setTooltip(tooltip);

Series rainfall = new ListSeries("Rainfall", 49.9, 71.5, 106.4, 129.2,
        144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4);
PlotOptionsColumn rainfallOptions = new PlotOptionsColumn();
SeriesTooltip rainfallTooltip = new SeriesTooltip();
rainfallTooltip.setPointFormat(
        "<span style=\"font-weight: bold; color: {series.color}\">"
                + "{series.name}</span>: <b>{point.y:.1f} mm</b> ");
rainfallOptions.setTooltip(rainfallTooltip);
rainfall.setPlotOptions(rainfallOptions);
configuration.addSeries(rainfall);

Series error = new RangeSeries("Rainfall error",
        new Number[] { 48, 51 }, new Number[] { 68, 73 },
        new Number[] { 92, 110 }, new Number[] { 128, 136 },
        new Number[] { 140, 150 }, new Number[] { 171, 179 },
        new Number[] { 135, 143 }, new Number[] { 142, 149 },
        new Number[] { 204, 220 }, new Number[] { 189, 199 },
        new Number[] { 95, 110 }, new Number[] { 52, 56 });
PlotOptionsErrorbar errorOptions = new PlotOptionsErrorbar();
SeriesTooltip errorTooltip = new SeriesTooltip();
errorTooltip.setPointFormat(
        "(error range: {point.low}-{point.high} mm)<br/>");
errorOptions.setTooltip(errorTooltip);
error.setPlotOptions(errorOptions);
configuration.addSeries(error);
```
