Error Charts lets you see margin of error or confidence level at a glance. Error Graph can be combined with any other Chart with axis including Line, Column, Bar, Area etc. Given example shows simple ASP.NET MVC Error Chart with Column Chart along with source code that you can try running locally.
@{ Layout = null; } <!DOCTYPE HTML> <html> <head> <script> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { title: { text: "Voltage Readings in an Experiment" }, axisY: { title: "Voltage (in millivolts)" }, toolTip: { shared: true }, data: [{ type: "column", name: "Observed", yValueFormatString: "#,##0.## mV", dataPoints: @Html.Raw(ViewBag.DataPoints1) }, { type: "error", name: "Actual", yValueFormatString: "#,##0.## mV", toolTipContent: "Actual: {y[0]} to {y[1]}", dataPoints: @Html.Raw(ViewBag.DataPoints2) }] }); chart.render(); } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script type="text/javascript" src="https://cdn.canvasjs.com/canvasjs.min.js"></script> </body> </html>
using ASPNET_MVC_ChartsDemo.Models; using Newtonsoft.Json; using System.Collections.Generic; using System.Web.Mvc; namespace ASPNET_MVC_ChartsDemo.Controllers { public class HomeController : Controller { // GET: Home public ActionResult Index() { List<DataPoint> dataPoints1 = new List<DataPoint>(); List<DataPoint> dataPoints2 = new List<DataPoint>(); dataPoints1.Add(new DataPoint("Reading 1", 71)); dataPoints1.Add(new DataPoint("Reading 2", 67)); dataPoints1.Add(new DataPoint("Reading 3", 55)); dataPoints1.Add(new DataPoint("Reading 4", 50)); dataPoints1.Add(new DataPoint("Reading 5", 66)); dataPoints1.Add(new DataPoint("Reading 6", 65)); dataPoints2.Add(new DataPoint("Reading 1", new double[] { 66, 75 })); dataPoints2.Add(new DataPoint("Reading 2", new double[] { 63, 70 })); dataPoints2.Add(new DataPoint("Reading 3", new double[] { 52, 57 })); dataPoints2.Add(new DataPoint("Reading 4", new double[] { 48, 52 })); dataPoints2.Add(new DataPoint("Reading 5", new double[] { 61, 69 })); dataPoints2.Add(new DataPoint("Reading 6", new double[] { 63, 67 })); ViewBag.DataPoints1 = JsonConvert.SerializeObject(dataPoints1); ViewBag.DataPoints2 = JsonConvert.SerializeObject(dataPoints2); return View(); } } }
using System; using System.Runtime.Serialization; namespace ASPNET_MVC_ChartsDemo.Models { //DataContract for Serializing Data - required to serve in JSON format [DataContract] public class DataPoint { public DataPoint(string label, dynamic y) { this.Label = label; this.Y = y; } //Explicitly setting the name to be used while serializing to JSON. [DataMember(Name = "label")] public string Label = ""; //Explicitly setting the name to be used while serializing to JSON. [DataMember(Name = "y")] public dynamic Y = null; } }
Dash type of stem and the whisker can be customized using stemDashType and whiskerDashType respectively. Some other commonly used customization options include stemColor, whiskerColor, etc.
Note For step by step instructions, follow our ASP.NET MVC Integration Tutorial