Range Column Charts, also referred as Vertical Range Column Charts, are similar to Column Charts except that they are drawn between a range of values - Low & High. The below example shows ASP.NET MVC Range 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", { theme: "light1", // "light1", "light2", "dark1", "dark2" animationEnabled: true, title: { text: "Annual High / Low Temperature - US Metropolitan Cities" }, axisX: { interval: 1 }, axisY: { includeZero: false, suffix: " °C" }, data: [{ type: "rangeColumn", indexLabel: "{y[#index]} °C", toolTipContent: "<b>{label}</b><br>Min: {y[0]} °C, Max: {y[1]} °C", dataPoints: @Html.Raw(ViewBag.DataPoints) }] }); 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> dataPoints = new List<DataPoint>(); dataPoints.Add(new DataPoint("Baltimore", new double[] { 18, 7 })); dataPoints.Add(new DataPoint("Boston", new double[] { 15, 7 })); dataPoints.Add(new DataPoint("Chicago", new double[] { 15, 5 })); dataPoints.Add(new DataPoint("Dallas", new double[] { 25, 14 })); dataPoints.Add(new DataPoint("Detroit", new double[] { 15, 5 })); dataPoints.Add(new DataPoint("Houston", new double[] { 27, 16 })); dataPoints.Add(new DataPoint("Los Angeles", new double[] { 24, 13 })); dataPoints.Add(new DataPoint("Washington ", new double[] { 19, 10 })); dataPoints.Add(new DataPoint("Seattle ", new double[] { 16, 8 })); dataPoints.Add(new DataPoint("New Orleans ", new double[] { 26, 16 })); dataPoints.Add(new DataPoint("Miami ", new double[] { 29, 21 })); ViewBag.DataPoints = JsonConvert.SerializeObject(dataPoints); 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, double[] 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 double[] Y = null; } }
The content of toolTip can be customized using the toolTipContent property. Some other commonly used customization options include showInLegend, shared(toolTip), etc.
Note For step by step instructions, follow our ASP.NET MVC Integration Tutorial