Line Chart

ASP.NET MVC Line Chart Sample using CanvasJS

Here is an example for adding Interactive Line Charts into your ASP.NET MVC Application using CanvasJS. Line charts allow you to customize colors of individual markers that lets you highlight a particular data point from the rest. You can selectively zoom & pan into a certain region to get a better picture when there are large number of data points.

Please refer to this tutorial for step by step instruction of adding charts to your ASP.Net MVC Application. We recommend that you download the Sample Visual Studio Project and try it on your own to understand the API better.


Download ASP.Net MVC Chart Samples

var chart = new CanvasJS.Chart("chartContainer", {
.
.
data: [{
    type: "line",
    dataPoints: [
        { y: 6, label: "Apple" },
	{ y: 4, label: "Mango" },
	{ y: 5, label: "Orange" },
    ]
}]
.
.
}

You can further customize these charts to enable features like Zooming, Panning, Exporting, etc. To know more about the available features, please refer to our getting started section.


@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <script type="text/javascript" src="http://canvasjs.com/assets/script/canvasjs.min.js"></script>
    <title>Line Chart</title>
</head>
<body>
    <div id="chartContainer"></div>

    <script type="text/javascript">
        window.onload = function () {
            var chart = new CanvasJS.Chart("chartContainer", {
                theme: "theme2",
                zoomEnabled: true,
                animationEnabled: true,
                title: {
                    text: "Line Chart in ASP.Net MVC using CanvasJS"
                },
                subtitles: [
                    {
                        text: "Try Resizing the Browser"
                    }
                ],
                data: [
                {
                    type: "line",
                    dataPoints: [
                        { x: 10, y: 71 },
                        { x: 20, y: 55 },
                        { x: 30, y: 50 },
                        { x: 40, y: 65 },
                        { x: 50, y: 95 },
                        { x: 60, y: 68 },
                        { x: 70, y: 28 },
                        { x: 80, y: 34 },
                        { x: 90, y: 14 },
                        { x: 100, y: 33 },
                        { x: 110, y: 42 },
                        { x: 120, y: 62 },
                    ],
                }
                ]
            });
            chart.render();
        };
    </script>

</body>
</html>			
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ASPNET_MVC_Samples.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Line()
        {
            return View();
        }
    }
}			


In order to provide better support,we have closed the comments and switched completely to our Forums.
If you have any questions, please feel free to ask in our forums.