---
product: "AG Charts"
title: "Error Bars"
description: "Error Bars visually represent the variability or uncertainty of data, indicating the range within which data values might fall."
enterprise: true
framework: vue
version: "14.3.0"
related:
    - title: "Cross Lines"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/axes-cross-lines/"
    - title: "Legend"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/legend/"
    - title: "Formatters"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/formatters/"
    - title: "Stylers"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/stylers/"
    - title: "Series Bars"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/bars/"
    - title: "Series Fills"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/fills/"
    - title: "Series Labels"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/series-labels/"
    - title: "Series Markers"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/markers/"
    - title: "Style Segments"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/style-segments/"
    - title: "Annotations"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/annotations/"
    - title: "Background Regions"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/background-regions/"
    - title: "Colour Scale"
      url: "https://www.ag-grid.com/charts/archive/14.3.0/vue/colour-scale/"
llms: "https://www.ag-grid.com/charts/archive/14.3.0/llms.txt"
---

# Error Bars

Error Bars visually represent the variability or uncertainty of data, indicating the range within which data values might fall.

## Single Error Bars

#### Single Error Bars

```ts
import { createApp, defineComponent, ref } from "vue";
import { AgCharts } from "ag-charts-vue3";
import type { AgChartOptions } from "ag-charts-types";
import {
  AnimationModule,
  BarSeriesModule,
  CategoryAxisModule,
  ContextMenuModule,
  CrosshairModule,
  ErrorBarsModule,
  LegendModule,
  ModuleRegistry,
  NumberAxisModule,
} from "ag-charts-enterprise";
import { getData } from "./data";

ModuleRegistry.registerModules([
  AnimationModule,
  BarSeriesModule,
  CategoryAxisModule,
  CrosshairModule,
  ErrorBarsModule,
  LegendModule,
  NumberAxisModule,
  ContextMenuModule,
]);

const ChartExample = defineComponent({
  template: `
    <ag-charts
      :options="options"
    />
  `,
  components: {
    "ag-charts": AgCharts,
  },
  setup(props) {
    const options = ref<AgChartOptions>({
      data: getData(),
      title: {
        text: "Monthly Dividends with 95% Confidence Intervals (%)",
      },
      series: [
        {
          type: "bar",
          xKey: "month",
          yKey: "dividends",
          yName: "Monthly Dividends (%)",
          errorBar: {
            yLowerKey: "lowerCI",
            yUpperKey: "upperCI",
          },
        },
      ],
    });

    return {
      options,
    };
  },
});

createApp(ChartExample).mount("#app");
```

[Live example: Single Error Bars](https://www.ag-grid.com/charts/archive/14.3.0/vue3/error-bars/examples/single-error-bars/)

This example adds Error Bars to a [Bar Series](https://www.ag-grid.com/charts/archive/14.3.0/vue/bar-series/) using the `errorBar` series option:

```js
{
    series: [
        {
            type: 'bar',
            xKey: 'month',
            yKey: 'dividends',
            errorBar: {
                yLowerKey: 'lowerCI',
                yUpperKey: 'upperCI',
            },
        },
    ],
}
```

In this configuration:

- `errorBar.yLowerKey` maps to the lower bound of the confidence interval.
- `errorBar.yUpperKey` maps to the upper bound of the confidence interval.

> **Note**
>
> Error Bars are only supported in [Bar](https://www.ag-grid.com/charts/archive/14.3.0/vue/bar-series/), [Line](https://www.ag-grid.com/charts/archive/14.3.0/vue/line-series/) and [Scatter](https://www.ag-grid.com/charts/archive/14.3.0/vue/scatter-series/) series.

## Double Error Bars

#### Double Error Bars

```ts
import { createApp, defineComponent, ref } from "vue";
import { AgCharts } from "ag-charts-vue3";
import type { AgChartOptions } from "ag-charts-types";
import {
  AnimationModule,
  ContextMenuModule,
  CrosshairModule,
  ErrorBarsModule,
  LegendModule,
  LineSeriesModule,
  ModuleRegistry,
  NumberAxisModule,
} from "ag-charts-enterprise";
import { getData } from "./data";

function customTooltipRenderer({ datum }) {
  return {
    heading: "",
    data: [
      {
        label: "Expiry",
        value: `${datum.expiryLo} to ${datum.expiryHi} months`,
      },
      { label: "Price", value: `${datum.priceLo} to ${datum.priceHi} pounds` },
    ],
  };
}

ModuleRegistry.registerModules([
  AnimationModule,
  CrosshairModule,
  ErrorBarsModule,
  LegendModule,
  LineSeriesModule,
  NumberAxisModule,
  ContextMenuModule,
]);

const ChartExample = defineComponent({
  template: `
    <ag-charts
      :options="options"
    />
  `,
  components: {
    "ag-charts": AgCharts,
  },
  setup(props) {
    const options = ref<AgChartOptions<DataType>>({
      data: getData(),
      title: {
        text: "Option Prices vs. Expiry with Confidence Intervals",
      },
      series: [
        {
          type: "line",
          xKey: "expiry",
          yKey: "price",
          errorBar: {
            xLowerKey: "expiryLo",
            xUpperKey: "expiryHi",
            yLowerKey: "priceLo",
            yUpperKey: "priceHi",
          },
          tooltip: { renderer: customTooltipRenderer },
        },
      ],
      axes: {
        x: {
          type: "number",
          title: {
            text: "Expiry Date (Months)",
          },
        },
        y: {
          type: "number",
          title: {
            text: "Option Price (£)",
          },
        },
      },
    });

    return {
      options,
    };
  },
});

createApp(ChartExample).mount("#app");
```

[Live example: Double Error Bars](https://www.ag-grid.com/charts/archive/14.3.0/vue3/error-bars/examples/double-error-bars/)

This example adds Double Error Bars to a Line Series using the `errorBar` series option:

```js
{
    series: [
        {
            type: 'line',
            xKey: 'expiry',
            yKey: 'price',
            errorBar: {
                xLowerKey: 'expiryLo',
                xUpperKey: 'expiryHi',
                yLowerKey: 'priceLo',
                yUpperKey: 'priceHi',
            },
            tooltip: { renderer: customTooltipRenderer },
        },
    ],
}
```

In this configuration:

- `errorBar.xLowerKey` and `errorBar.xUpperKey` denote the x-axis bounds.
- `errorBar.yLowerKey` and `errorBar.yUpperKey` denote the y-axis bounds.

A custom [Tooltip](https://www.ag-grid.com/charts/archive/14.3.0/vue/tooltips/) is also provided to the series `tooltip` option to display the x-axis and y-axis bounds. The x and y keys and names are available to the renderer when Error Bars are enabled.

> **Note**
>
> Double Error Bars require the x-axis to be a [Number Axis](https://www.ag-grid.com/charts/archive/14.3.0/vue/axes-types/#number), limiting them to [Line](https://www.ag-grid.com/charts/archive/14.3.0/vue/line-series/) and [Scatter](https://www.ag-grid.com/charts/archive/14.3.0/vue/scatter-series/) series.

## Customisation

#### Customisation

```ts
import { createApp, defineComponent, ref } from "vue";
import { AgCharts } from "ag-charts-vue3";
import type { AgChartOptions } from "ag-charts-types";
import {
  AnimationModule,
  CategoryAxisModule,
  ContextMenuModule,
  CrosshairModule,
  ErrorBarsModule,
  LegendModule,
  ModuleRegistry,
  NumberAxisModule,
  ScatterSeriesModule,
} from "ag-charts-enterprise";
import { getData } from "./data";

ModuleRegistry.registerModules([
  AnimationModule,
  CategoryAxisModule,
  CrosshairModule,
  ErrorBarsModule,
  LegendModule,
  NumberAxisModule,
  ScatterSeriesModule,
  ContextMenuModule,
]);

const ChartExample = defineComponent({
  template: `
    <ag-charts
      :options="options"
    />
  `,
  components: {
    "ag-charts": AgCharts,
  },
  setup(props) {
    const options = ref<AgChartOptions>({
      data: getData(),
      title: {
        text: "Volume-Pressure Relationship with Confidence Intervals",
      },
      series: [
        {
          type: "scatter",
          xKey: "vol",
          yKey: "pres",
          errorBar: {
            xLowerKey: "volLower",
            xUpperKey: "volUpper",
            yLowerKey: "presLower",
            yUpperKey: "presUpper",
            stroke: "pink",
            strokeWidth: 2,
            cap: {
              stroke: "red", // otherwise inherits `pink` from whisker
              strokeWidth: 5, // otherwise inherits `2` from whisker
              length: 25,
            },
          },
        },
      ],
    });

    return {
      options,
    };
  },
});

createApp(ChartExample).mount("#app");
```

[Live example: Customisation](https://www.ag-grid.com/charts/archive/14.3.0/vue3/error-bars/examples/customisation/)

This example shows different Error Bar Cap and Whiskers customisations:

```js
{
    errorBar: {
        // ...
        stroke: 'pink', // Whisker stroke colour
        strokeWidth: 2, // Whisker stroke width
        cap: {
            stroke: 'red', // Cap stroke colour (otherwise inherits from whisker)
            strokeWidth: 5, // Cap stroke width (otherwise inherits from whisker)
            length: 25, // Cap length as an absolute width
        },
    },
}
```

The Cap length can also be customised as a ratio relative to series shape using `lengthRatio`.

> **Note**
>
> The default Cap length is determined based on the type of series:
>
> - For [Line](https://www.ag-grid.com/charts/archive/14.3.0/vue/line-series/) and [Scatter](https://www.ag-grid.com/charts/archive/14.3.0/vue/scatter-series/) series, it defaults to the [Marker](https://www.ag-grid.com/charts/archive/14.3.0/vue/markers/) size.
> - For [Bar](https://www.ag-grid.com/charts/archive/14.3.0/vue/bar-series/#simple-bar) series, it defaults to 30% of the bar width.

[Stylers](https://www.ag-grid.com/charts/archive/14.3.0/vue/stylers/) can also be used for customisation using the `errorBar.itemStyler` property. The `params` object includes properties from the Series and Error Bars.

## Offset Labels

By default, [series label placements](https://www.ag-grid.com/charts/archive/14.3.0/vue/series-labels/#placement) and spacing are relative to the end of the Error Bar. Set `errorBar.offsetLabels` to `false` to position labels against the series item instead.

#### Offset Labels

```ts
import { createApp, defineComponent, ref } from "vue";
import { AgCharts } from "ag-charts-vue3";
import type { AgChartOptions } from "ag-charts-types";
import {
  BarSeriesModule,
  CategoryAxisModule,
  ErrorBarsModule,
  ModuleRegistry,
  NumberAxisModule,
} from "ag-charts-enterprise";
import { getData } from "./data";
import clone from "clone";

ModuleRegistry.registerModules([
  BarSeriesModule,
  CategoryAxisModule,
  ErrorBarsModule,
  NumberAxisModule,
]);

const ChartExample = defineComponent({
  template: `
    <div class="example-controls">
      <div class="controls-row">
        <span>Offset Labels:</span>
        <div class="button-group" role="group" aria-label="Offset Labels">
          <input type="radio" id="offset-labels-true" name="offset-labels" value="true" checked="" v-on:change="offsetLabelsChange($event)">
            <label for="offset-labels-true">true</label>
            <input type="radio" id="offset-labels-false" name="offset-labels" value="false" v-on:change="offsetLabelsChange($event)">
              <label for="offset-labels-false">false</label>
            </div>
          </div>
        </div>
        <ag-charts
          :options="options"
        />
  `,
  components: {
    "ag-charts": AgCharts,
  },
  setup(props) {
    const options = ref<AgCartesianChartOptions>({
      data: getData(),
      seriesArea: { padding: { top: 10 } },
      title: {
        text: "Monthly Dividends with 95% Confidence Intervals (%)",
      },
      series: [
        {
          type: "bar",
          xKey: "month",
          yKey: "dividends",
          yName: "Monthly Dividends (%)",
          label: {
            placement: "outside-end",
            border: {},
            fill: { ref: "backgroundColor" },
            collision: { alwaysShow: true },
          },
          errorBar: {
            yLowerKey: "lowerCI",
            yUpperKey: "upperCI",
          },
        },
      ],
    });

    const offsetLabelsChange = (event) => {
      const optionsCopy = clone(options.value);

      const series = optionsCopy.series[0];
      series.errorBar.offsetLabels = event.target.value === "true";

      options.value = optionsCopy;
    };

    return {
      options,
      offsetLabelsChange,
    };
  },
});

createApp(ChartExample).mount("#app");
```

[Live example: Offset Labels](https://www.ag-grid.com/charts/archive/14.3.0/vue3/error-bars/examples/offset-labels/)

```js
{
    errorBar: {
        // ...
        offsetLabels: false,
    },
}
```

> **Note**
>
> Error Bars are always treated as obstacles by label [Collision Avoidance](https://www.ag-grid.com/charts/archive/14.3.0/vue/series-labels/#collision-avoidance). Labels that collide with an Error Bar move to a fallback `placement` or are hidden, depending on the label `collision` options.

## API Reference

#### Error Bar Options

| Property | Type | Default | Description |
| --- | --- | --- | --- |
| xLowerKey | DatumKey |  | The key to use to retrieve lower bound error values from the x-axis data. |
| xUpperKey | DatumKey |  | The key to use to retrieve upper bound error values from the x-axis data. |
| yLowerKey | DatumKey |  | The key to use to retrieve lower bound error values from the y-axis data. |
| yUpperKey | DatumKey |  | The key to use to retrieve upper bound error values from the y-axis data. |
| xLowerName | string |  | Human-readable description of the lower bound error value for the x-axis. This is the value to use in tooltips or labels. |
| xUpperName | string |  | Human-readable description of the upper bound error value for the x-axis. This is the value to use in tooltips or labels. |
| yLowerName | string |  | Human-readable description of the lower bound error value for the y-axis. This is the value to use in tooltips or labels. |
| yUpperName | string |  | Human-readable description of the upper bound error value for the y-axis. This is the value to use in tooltips or labels. |
| itemStyler | Styler |  | Function used to return formatting for individual error bars, based on the given parameters. |
| cap | ErrorBarCapOptions |  | Options to style error bars' caps |
| cap.length | PixelSize |  | Absolute length of caps in pixels. |
| cap.lengthRatio | Ratio |  | Length of caps relative to the shape used by the series. |
| cap.visible | boolean |  | Whether to display the error bars. |
| cap.stroke | CssColor \| AgColorRef \| AgColorRefMixOnto \| AgColorRefMixOntoColor |  | The colour for the stroke. |
| cap.strokeWidth | PixelSize |  | The width of the stroke in pixels. |
| cap.strokeOpacity | Opacity |  | The opacity of the stroke colour. |
| cap.lineDash | PixelSize[] |  | An array specifying the length in pixels of alternating dashes and gaps. |
| cap.lineDashOffset | PixelSize |  | The initial offset of the dashed line in pixels. |
| offsetLabels | boolean | true | Whether series labels are positioned past the error bar instead of against the series shape. Labels that collide with an error bar follow the label's collision options either way. |
| visible | boolean |  | Whether to display the error bars. |
| stroke | CssColor \| AgColorRef \| AgColorRefMixOnto \| AgColorRefMixOntoColor |  | The colour for the stroke. |
| strokeWidth | PixelSize |  | The width of the stroke in pixels. |
| strokeOpacity | Opacity |  | The opacity of the stroke colour. |
| lineDash | PixelSize[] |  | An array specifying the length in pixels of alternating dashes and gaps. |
| lineDashOffset | PixelSize |  | The initial offset of the dashed line in pixels. |
