CanvasJS allows you to create Multi Series Spline Area Chart by adding more than one data series. Given example shows Multi Series Spline Area 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", { animationEnabled: true, theme: "light2", title: { text: "Website Visitor Analysis" }, axisX: { valueFormatString: "DD MMM" }, axisY: { title: "Number of Visits" }, toolTip: { shared: true }, data: [{ type: "splineArea", name: "Total Visit", xValueType: "dateTime", dataPoints: @Html.Raw(ViewBag.DataPoints1) }, { type: "splineArea", name: "Unique Visit", xValueType: "dateTime", dataPoints: @Html.Raw(ViewBag.DataPoints2) }] }); chart.render(); } </script> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <script 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(1509647400000, 1100)); dataPoints1.Add(new DataPoint(1509733800000, 700)); dataPoints1.Add(new DataPoint(1509820200000, 943)); dataPoints1.Add(new DataPoint(1509906600000, 658)); dataPoints1.Add(new DataPoint(1509993000000, 734)); dataPoints1.Add(new DataPoint(1510079400000, 963)); dataPoints1.Add(new DataPoint(1510165800000, 847)); dataPoints1.Add(new DataPoint(1510252200000, 1500)); dataPoints1.Add(new DataPoint(1510338600000, 869)); dataPoints1.Add(new DataPoint(1510425000000, 710)); dataPoints1.Add(new DataPoint(1510511400000, 970)); dataPoints1.Add(new DataPoint(1510597800000, 1050)); dataPoints1.Add(new DataPoint(1510684200000, 1300)); dataPoints1.Add(new DataPoint(1510770600000, 1400)); dataPoints2.Add(new DataPoint(1509647400000, 700)); dataPoints2.Add(new DataPoint(1509733800000, 560)); dataPoints2.Add(new DataPoint(1509820200000, 540)); dataPoints2.Add(new DataPoint(1509906600000, 400)); dataPoints2.Add(new DataPoint(1509993000000, 544)); dataPoints2.Add(new DataPoint(1510079400000, 693)); dataPoints2.Add(new DataPoint(1510165800000, 657)); dataPoints2.Add(new DataPoint(1510252200000, 1330)); dataPoints2.Add(new DataPoint(1510338600000, 639)); dataPoints2.Add(new DataPoint(1510425000000, 506)); dataPoints2.Add(new DataPoint(1510511400000, 660)); dataPoints2.Add(new DataPoint(1510597800000, 906)); dataPoints2.Add(new DataPoint(1510684200000, 900)); dataPoints2.Add(new DataPoint(1510770600000, 1001)); 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(double x, double y) { this.x = x; this.Y = y; } //Explicitly setting the name to be used while serializing to JSON. [DataMember(Name = "x")] public Nullable<double> x = null; //Explicitly setting the name to be used while serializing to JSON. [DataMember(Name = "y")] public Nullable<double> Y = null; } }
Setting showInLegend to true enabled legends for all the data-series present in the chart. The text in the legend can changed using legendText property. Other commonly used customization options include color, fillOpacity, markerType, etc.
Note For step by step instructions, follow our ASP.NET MVC Integration Tutorial