CanvasJS Charts render or update huge data-sets in a matter of milliseconds without any performance lag. API is simple and easy to use. The given example includes source code that you can try running locally.
@{ Layout = null; } <!DOCTYPE HTML> <html> <head> <script> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { zoomEnabled: true, animationEnabled: true, title: { text: "Try Zooming - Panning" }, data: [{ type: "line", dataPoints: @Html.Raw(ViewBag.DataPoints) // random data }] }); var startTime = new Date(); chart.render(); var endTime = new Date(); document.getElementById("timeToRender").innerHTML = "Time to Render: " + (endTime - startTime) + "ms"; } </script> <style> #timeToRender { position: absolute; top: 10px; font-size: 20px; font-weight: bold; background-color: #d85757; padding: 0px 4px; color: #ffffff; } </style> </head> <body> <div id="chartContainer" style="height: 370px; width: 100%;"></div> <span id="timeToRender"></span> <script src="https://cdn.canvasjs.com/canvasjs.min.js"></script> </body> </html>
using ASPNET_MVC_ChartsDemo.Models; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Web.Mvc; namespace ASPNET_MVC_ChartsDemo.Controllers { public class HomeController : Controller { // GET: Home public ActionResult Index() { double count = 50000, y = 100; Random random = new Random(); List<DataPoint> dataPoints = new List<DataPoint>(); for (int i = 0; i < count; i++) { y += random.Next(-5, 6); dataPoints.Add(new DataPoint(i, y)); } ViewBag.DataPoints = JsonConvert.SerializeObject(dataPoints); return View(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Web; 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; } }
Marker size can be customized using markerSize property. Setting markerSize to zero in charts with large number of data-point enhances the performance. Other commonly used customization options include lineColor, lineDashType, etc.
Note For step by step instructions, follow our ASP.NET MVC Integration Tutorial