Error Bar Chart in TypeScript Charts

Error Bar

Error bars are graphical representations of the variability of data and are used on graphs to indicate the error or uncertainty in a reported measurement.

The error bar configuration is set on the errorBar property of each series. To render error bars, configure the chart as follows:

  • Set visibility: Set the visible property of the series errorBar configuration to true for the error bars to be displayed.

  • Inject the ErrorBar and LineSeries modules: Use Chart.Inject(LineSeries, ErrorBar) to register both the ErrorBar and the LineSeries modules. The LineSeries module is required because the sample series uses type: 'Line'. Replace it with the appropriate series module for your chart type.

import { Chart, LineSeries, ErrorBar } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        errorBar: {
            visible: true
        }, 
        marker: {
            visible: true
        }, 
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8 },
    { x: 2007, y: 7.2 },
    { x: 2008, y: 6.8 },
    { x: 2009, y: 10.7 },
    { x: 2010, y: 10.8 },
    { x: 2011, y: 9.8 }
];

Customizing error bar

Set the type property to choose how the error bar value is calculated. Available types are Fixed, Percentage, StandardDeviation, StandardError, and Custom. For custom values, also configure the horizontal and vertical positive and negative error values (verticalError, horizontalError, verticalPositiveError, verticalNegativeError, horizontalPositiveError, horizontalNegativeError).

import { Chart, LineSeries, ErrorBar } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        errorBar: {
            visible: true,
            type: 'Custom',
            mode: 'Both',
            verticalPositiveError: 2,
            horizontalPositiveError: 1,
            verticalNegativeError: 2,
            horizontalNegativeError: 1
        }, 
        marker: {
            visible: true
        }, 
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8 }, 
    { x: 2007, y: 7.2 },
    { x: 2008, y: 6.8 }, 
    { x: 2009, y: 5.7 },
    { x: 2010, y: 8.8 }, 
    { x: 2011, y: 9.8 }
];

Error bar mode

The error bar mode defines the direction in which the error bar line is drawn. Set this property to draw error bars horizontally, vertically, or on both sides. Available modes are Vertical, Horizontal, and Both. The default mode is Vertical.

import { Chart, LineSeries, ErrorBar } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        errorBar: {
            visible: true,
            mode: 'Horizontal'
        }, 
        marker: {
            visible: true
        }, 
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8 }, 
    { x: 2007, y: 7.2 },
    { x: 2008, y: 6.8 }, 
    { x: 2009, y: 5.7 },
    { x: 2010, y: 8.8 }, 
    { x: 2011, y: 9.8 }
];

Error bar direction

Set the direction property to indicate which side of the data point the error bar is drawn on. Available directions are Plus, Minus, and Both. The default direction is Both.

import { Chart, LineSeries, ErrorBar } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        errorBar: {
            visible: true,
            mode:'Vertical',
            direction:'Minus'
        }, 
        marker: {
            visible: true
        }, 
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8 },
    { x: 2007, y: 7.2 },
    { x: 2008, y: 6.8 },
    { x: 2009, y: 10.7 },
    { x: 2010, y: 10.8 },
    { x: 2011, y: 9.8 }
];

Customizing error bar cap

Use the errorBarCap property to customize the length, width, and color of the error bar caps. Sub-properties include length, width, opacity and color.

import { Chart, LineSeries, ErrorBar } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        errorBar: {
            visible: true,
            errorBarCap:{
                length:10,
                width:10,
                color:'#0000ff'
            }
        },
        marker: {
            visible: true
        }, 
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8 },
    { x: 2007, y: 7.2 },
    { x: 2008, y: 6.8 },
    { x: 2009, y: 10.7 },
    { x: 2010, y: 10.8 },
    { x: 2011, y: 9.8 }
];

Customizing error bar color

Set the errorBarColorMapping property to the name of the data field whose values determine the error bar color for each point. You can also set per-point positive and negative error values using the verticalPositiveError, verticalNegativeError, horizontalPositiveError, and horizontalNegativeError properties. Use verticalError or horizontalError when you want a single value applied to both directions per point.

import { Chart, LineSeries, ErrorBar } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        errorBar: {
            visible: true,
            errorBarColorMapping: 'color',
            verticalError: 'error'
        }, 
        marker: {
            visible: true
        },
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)'
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8, color: 'red', error: 4 },
    { x: 2007, y: 7.2, color: 'blue', error: 3 },
    { x: 2008, y: 6.8, color: 'green', error: 2 },
    { x: 2009, y: 10.7, color: 'orange', error: 1 },
    { x: 2010, y: 8.8, color: 'yellow', error: 3 },
    { x: 2011, y: 9.8, color: 'grey', error: 2 }
];

Events

Series render

The seriesRender event enables modification of series properties (for example, data, fill, or name) immediately before rendering. Use this event to adjust series appearance or to dynamically swap data sources.

import { Chart, LineSeries, ErrorBar, ISeriesRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        width: 2,
        errorBar: {
            visible: true
        }, 
        marker: {
            visible: true
        }, 
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)',
    seriesRender: (args: ISeriesRenderEventArgs) => {
        args.fill = '#ff6347';
    }
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8 },
    { x: 2007, y: 7.2 },
    { x: 2008, y: 6.8 },
    { x: 2009, y: 10.7 },
    { x: 2010, y: 10.8 },
    { x: 2011, y: 9.8 }
];

Point render

The pointRender event provides a hook to customize each data point (for example, marker shape, border, or fill) before it is drawn. Use this to apply per-point styling rules or conditional formatting.

import { Chart, LineSeries, ErrorBar, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(LineSeries, ErrorBar);

let chart: Chart = new Chart({
    primaryXAxis: {
        minimum: 2005, 
        maximum: 2012, 
        interval: 1,
        title: 'Year'
    },
    primaryYAxis: {
        minimum: 3, maximum: 12,
        interval: 1, title: 'Percentage',
        labelFormat: '{value}%'
    },
    series: [{
        dataSource: chartData,
        xName: 'x', yName: 'y',
        width: 2,
        errorBar: {
            visible: true
        }, 
        marker: {
            visible: true
        }, 
        animation: { enable: false },
        type: 'Line'
    }],
    title: 'Unemployment rate (%)',
    pointRender: (args: IPointRenderEventArgs) => {
        if (args.point.index % 2 !== 0) {
            args.fill = '#ff6347';
        }
        else {
            args.fill = '#009cb8';
        }
    }
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>
export let chartData: Object[] = [
    { x: 2006, y: 7.8 },
    { x: 2007, y: 7.2 },
    { x: 2008, y: 6.8 },
    { x: 2009, y: 10.7 },
    { x: 2010, y: 10.8 },
    { x: 2011, y: 9.8 }
];

Troubleshooting

The following list describes common issues you may encounter when working with Error Bars and how to resolve them.

Error bars do not render: Confirm the errorBar property is configured on each series and that its visible property is set to true. Also ensure the ErrorBar module is registered. If your series uses a specific type (for example, Line), register the corresponding series module alongside ErrorBar (for example, Chart.Inject(LineSeries, ErrorBar)), or import both modules directly from @syncfusion/ej2-charts using ES module syntax.

Custom error values do not change: Set the error bar type to Custom to enable per-point positive/negative overrides; otherwise the value is calculated from a fixed percentage or standard deviation.

Events fire but changes are not visible: The seriesRender and pointRender events let you modify the rendered series or point. Mutate the args object (for example, args.fill) inside the handler; setting properties on the series object directly is overwritten during rendering.

See also