# Error Bars

The Chart enables you to implement error bars which show the variability of data.

The low and high value for the error bars can be either bound to the data or calculated from the point or series values. The error bars are specified as part of the series definition.

The following series types support error bars:

* Area
* Vertical Area
* Column
* Bar
* Line
* Vertical Line
* Scatter
* ScatterLine

## Binding to Categorical Series

To bind the low and high values of the error bars when using categorical series, set the [`ErrorLowField`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/categoricalerrorbarsbuilder#lowfieldsystemstring) and [`ErrorHighField`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/categoricalerrorbarsbuilder#highfieldsystemstring) options to the fields in the data that hold the low and high value.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Series(s => s
            .Column(new object[] {
                new {
                    value = 4.743,
                    low = 4.5,
                    high = 5
                },
                new {
                    value = 7.295,
                    low = 7,
                    high = 8
                },
                new {
                    value = 6.376,
                    low = 5,
                    high = 6.5
                }
            })
            .ErrorLowField("low")
            .ErrorHighField("high")
        )
    )
```

## Binding to Scatter Series

You can also display error bars for the series `x` or `y` value, or both. To set the low and high fields for the series `x` value, set the [`XErrorLowField`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/scattererrorbarsbuilder#xlowfieldsystemstring) and [`XErrorHighField`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/scattererrorbarsbuilder#xhighfieldsystemstring) series options. To specify the low and high fields for the `y` value of the series, use the [`YErrorLowField`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/scattererrorbarsbuilder#ylowfieldsystemstring) and [`YErrorHighField`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/scattererrorbarsbuilder#yhighfieldsystemstring) options.

The following example demonstrates how to bind the error bars for the `x` value of the series.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
            .Name("chart")
            .Series(s => s
                .Scatter(new object[] {
                    new {
                        x= 6.4,
                        y= 13.4,
                        low= 5,
                        high= 7
                    },
                    new {
                        x= 1.7,
                        y= 11,
                        low= 1,
                        high= 3
                    }, new {
                        x= 5.4,
                        y= 8,
                        low= 3,
                        high= 6}
                })
                .XErrorLowField("low")
                .XErrorHighField("high")
            )
    )
```

The following example demonstrates how to bind the error bars for the `y` value of the series.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
            .Name("chart")
            .Series(s => s
                .Scatter(new object[] {
                    new {
                        x= 6.4,
                        y= 13.4,
                        low= 12,
                        high= 17
                    },
                    new {
                        x= 1.7,
                        y= 11,
                        low= 11,
                        high= 14
                    }, new {
                        x= 5.4,
                        y= 8,
                        low= 5,
                        high= 8}
                })
                .YErrorLowField("low")
                .YErrorHighField("high")
            )
    )
```

## Setting the Error Bar Values

You can calculate the low and high values of the error bars based on the series point values. To set the error bars value for categorical series, specify the [`ErrorBars.Value`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/categoricalerrorbarsbuilder#valuesystemstring) option. For scatter series, set the [`ErrorBars.XValue`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/scattererrorbarsbuilder#xvaluesystemstring) or [`ErrorBars.YValue`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/scattererrorbarsbuilder#yvaluesystemstring) options, or both.

### Setting Numeric Values

If the value of the error bar is set to a number (must not be negative), the low and high value are calculated by subtracting or adding the value to the series value.

The following example demonstrates how to set a numeric value for the categorical series.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Series(s => s
            .Column(new object[] {
                new {
                    value = 4.743
                },
                new {
                    value = 7.295
                },
                new {
                    value = 6.376
                }
            })
            .ErrorBars(err => err.Value("1"))
        )
    )
```

The following example demonstrates how to set a numeric value for the scatter series.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Series(s => s
            .Scatter(new object[] {
                new {
                    x = 6.4,
                    y = 13.4
                },
                new {
                    x = 1.7,
                    y = 11
                },
                new {
                    x = 5.4,
                    y = 8
                }
            })
            .ErrorBars(err => err.YValue("1"))
        )
    )
```

### Setting Percentage Values

You can also set the difference of the point value as percentage by setting a string value in the `"percenatage(n)"` format where `n` indicates the percent value.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Series(s => s
            .Column(new object[] {
                new {
                    value = 4.743
                },
                new {
                    value = 7.295
                },
                new {
                    value = 6.376
                }
            })
        )
        .ErrorBars(err => err.Value("percentage(20)"))
    )
```

### Setting Statistical Values

The error bars support statistical calculations based on the series data. The supported types are the [standard error](http://en.wikipedia.org/wiki/Standard_error) and [population standard deviation](http://en.wikipedia.org/wiki/Standard_deviation). To specify that the standard error has to be used, set `"stderr"` as a value. To use standard deviation, set `"stddev"` with an optional number between parentheses appended at the end. The number will be multiplied by the calculated standard deviation value.

The following example demonstrates how to use the standard error type.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Series(s => s
            .Column(new object[] {
                new {
                    value = 4.743
                },
                new {
                    value = 7.295
                },
                new {
                    value = 6.376
                }
            })
        )
        .ErrorBars(err => err.Value("stderr"))
    )
```

The following example demonstrates how to use the standard deviation type.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Series(s => s
            .Column(new object[] {
                new {
                    value = 4.743
                },
                new {
                    value = 7.295
                },
                new {
                    value = 6.376
                }
            })
        )
        .ErrorBars(err => err.Value("stddev(0.5)"))
    )
```

### Calculating Low and High Values

If you need a custom algorithm to calculate the low and high value, specify a function. The function accepts an object and returns a valid error bar value.

The following fields are available as object parameters:

* `dataItem`—The point data item.
* `value`—The point value.
* `index`—The point index in the series data.
* `category`—The point category value if a categorical chart is used.
* `series`—The series configuration.

The following example demonstrates how to use different percentages for the low and high values.

```Razor HtmlHelper
    @(Html.Kendo().Chart()
        .Name("chart")
        .Series(s => s
            .Column(new object[] {
                new {
                    value = 4.743
                },
                new {
                    value = 7.295
                },
                new {
                    value = 6.376
                }
            })
        )
        .ErrorBars(err => err.ValueHandler("calculateError"))
    )
```

```JavaScript
    function calculateError(data) {
        var value = data.value;
        var lowPercentage = value * 0.05;
        var highPercentage = value * 0.1;

        return [lowPercentage, highPercentage];
    }
```

## See Also

* [Using the API of the Chart HtmlHelper for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/chart-api/index)
* [Basic Usage of the Area Chart for ASP.NET MVC (Demos)](https://demos.telerik.com/aspnet-mvc/area-charts/index)
* [Server-Side API of the Chart for ASP.NET MVC](https://www.telerik.com/aspnet-mvc/documentation/api/chart)
