# ErrorBar

ErrorBar series represent error and standard deviations in FlexChart. Learn more about the ErrorBar in MVC documentation.

## Content

ErrorBar chart enables user to spot margins of error and standard deviations at a glance. It can be shown as a standard error amount, a percentage, or a standard deviation. User can also set its own custom values to display the exact error amounts in the Chart. Generally, results of scientific studies or experimental sciences use error bars in charts to depict variations in data from original values.
This topic describes how to use ErrorBar series in your FlexChart to represent error and standard deviations. To work with ErrorBar Series, you need to create an instance of **FlexChart** class, which is a part of **C1.Web.Mvc** namespace.
Follow the steps given below to get started:
![Showing ErrorBAr series in FlexChart](https://cdn.mescius.io/document-site-files/images/2b3ac322-100e-4637-958d-fb40dcda3f44/images/errorbarseries.png)

### Create a Datasource for FlexChart

1. Add a new class to the **Models** folder (for example: `PopulationByCountry.cs`).
2. Add the following code to the new model to define a class which will serve as a datasource for the FlexChart.

    ```csharp
    using System.Collections.Generic;
    namespace ErrorBarSeries.Models
    {
        public class PopulationByCountry
        {
            public string Country { get; set; }
            public int Population { get; set; }
            public static List<PopulationByCountry> GetData()
            {
                string[] countries = "China,India,USA,Indonesia,Brazil".Split(new char[] { ',' });
                int[] population = new int[] { 1380, 1310, 325, 260, 206 };
                var data = new List<PopulationByCountry>();
                for (var i = 0; i < countries.Length; i++)
                {
                    data.Add(new PopulationByCountry()
                    {
                        Country = countries[i],
                        Population = population[i]
                    });
                }
                return data;
            }
        }
    }
    ```

### Add ErrorBar Series to FlexChart

To add a FlexChart to the application, follow these steps:

**Add a new Controller**

1. In the **Solution Explorer**, right click the folder **Controllers.**
2. From the context menu, select **Add \| Controller**. The **Add Scaffold** dialog appears.
3. In the **Add Scaffold** dialog, follow these steps:
    1. Select **MVC 5 Controller - Empty** template.
    2. Set name of the controller (for example: `ErrorBarController`).
    3. Click **Add**.
4. Include the MVC references as shown below.
<br>
    ```csharp
    using C1.Web.Mvc;
    using C1.Web.Mvc.Serializition;
    using C1.Web.Mvc.Chart;
    ```
5. Replace the method Index() with the following method.
<br>
    ```csharp
    public ActionResult Index()
            {
                return View(PopulationByCountry.GetData());
            }
    ```

**Add a View for the Controller**

1. From the **Solution Explorer**, expand the folder **Controllers** and double click the `ErrorBarController.`
2. Place the cursor inside the method `Index()`.
3. Right click and select **Add View**. The **Add View** dialog appears.
4. In the **Add View** dialog, verify that the view name is **Index** and View engine is **Razor (CSHTML).**
5. Click **Add**. A view is added for the controller.

    ```razor
    @model IEnumerable<PopulationByCountry>
    @using ErrorBarSeries.Models;
    <br />
    <br />
    @(Html.C1().FlexChart()
    .Bind("Country", "Population", Model)
    .Series(ser =>
    {
        ser.AddErrorBar().Value(50)
        .ErrorBarStyle(errorBarStyle => errorBarStyle.Fill("#e6e6e6").Stroke("#918254").StrokeWidth(2));
    })
    .Height("300px")
    )
    ```

### Build and Run the Project

1. Click **Build \| Build Solution** to build the project.
2. Press **F5** to run the project.

> Append the folder name and view name to the generated URL (for example: http://localhost:1234/**ErrorBar/Index**) in the address bar of the browser to see the view.