Spline Charts, also called Smoothed / Curved Line Chart, are like Line Charts except that data points are connected using smooth curved lines. The given example shows ASP.NET MVC Spline 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, title: { text: "Ice Cream Sales Over a Month" }, axisX: { valueFormatString: "DD MMM" }, axisY: { title: "Sales (in USD)", prefix: "$" }, data: [{ type: "spline", xValueType: "dateTime", xValueFormatString: "DD MMM", yValueFormatString: "$#,###", dataPoints: @Html.Raw(ViewBag.DataPoints) }] }); 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> dataPoints = new List<DataPoint>(); dataPoints.Add(new DataPoint(1496255400000, 2500)); dataPoints.Add(new DataPoint(1496341800000, 2790)); dataPoints.Add(new DataPoint(1496428200000, 3380)); dataPoints.Add(new DataPoint(1496514600000, 4940)); dataPoints.Add(new DataPoint(1496601000000, 4020)); dataPoints.Add(new DataPoint(1496687400000, 3390)); dataPoints.Add(new DataPoint(1496773800000, 4200)); dataPoints.Add(new DataPoint(1496860200000, 3150)); dataPoints.Add(new DataPoint(1496946600000, 3230)); dataPoints.Add(new DataPoint(1497033000000, 4200)); dataPoints.Add(new DataPoint(1497119400000, 5210)); dataPoints.Add(new DataPoint(1497205800000, 4940)); dataPoints.Add(new DataPoint(1497292200000, 3500)); dataPoints.Add(new DataPoint(1497378600000, 3790)); dataPoints.Add(new DataPoint(1497465000000, 3230)); dataPoints.Add(new DataPoint(1497551400000, 2900)); dataPoints.Add(new DataPoint(1497637800000, 3080)); dataPoints.Add(new DataPoint(1497724200000, 3370)); dataPoints.Add(new DataPoint(1497810600000, 2880)); dataPoints.Add(new DataPoint(1497897000000, 3170)); dataPoints.Add(new DataPoint(1497983400000, 3280)); dataPoints.Add(new DataPoint(1498069800000, 4070)); dataPoints.Add(new DataPoint(1498156200000, 5280)); dataPoints.Add(new DataPoint(1498242600000, 4970)); dataPoints.Add(new DataPoint(1498329000000, 2560)); dataPoints.Add(new DataPoint(1498415400000, 2790)); dataPoints.Add(new DataPoint(1498501800000, 3800)); dataPoints.Add(new DataPoint(1498588200000, 4400)); dataPoints.Add(new DataPoint(1498674600000, 4020)); dataPoints.Add(new DataPoint(1498761000000, 3900)); 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(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; } }
The markers can be changed using markerType property. You can also customize the size and the color of the markers using markerSize and markerColor. Other frequently used customization options are markerBorderColor, animationEnabled, zoomEnabled, etc.
Note For step by step instructions, follow our ASP.NET MVC Integration Tutorial