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:
PopulationByCountry.cs
).PopulationByCountry.cs |
Copy Code
|
---|---|
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; } } } |
To add a FlexChart to the application, follow these steps:
Add a new Controller
ErrorBarController
).C# |
Copy Code
|
---|---|
using C1.Web.Mvc; using C1.Web.Mvc.Serializition; using C1.Web.Mvc.Chart; |
C# |
Copy Code
|
---|---|
public ActionResult Index() { return View(PopulationByCountry.GetData()); } |
Add a View for the Controller
ErrorBarController.
Index()
.Index.cshtml |
Copy Code
|
---|---|
@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") ) |