namespace ContsoSite.Controllers { public class DashboardController : Controller { // // GET: /Dashboard/ public ActionResult Index() { return View(); } public JsonResult GetData() { using (var db = new ContosoUniversityEntities ()) { var result = (from tags in db.Courses orderby tags.Title ascending select new { tags.Title, tags.Credits }).ToList(); return Json(JsonConvert.SerializeObject(result), JsonRequestBehavior.AllowGet); //return Content(JsonConvert.SerializeObject(_dataPoints), "application/json"); } } public ActionResult Dashboard_Pie() { return View(); } public ActionResult Dashboard_AreaChart() { return View(); } public ActionResult Dashboard_ColumnChart() { return View(); } } }
@model IEnumerable<ContsoSite.Models.ContosoUniversityEntities> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <script src="~/Scripts/canvasjs.min.js"></script> @*<script src="~/Scripts/canvasjs.js"></script>*@ @*<script src="~/Scripts/excanvas.js"></script>*@ <script type="text/javascript"> $(document).ready(function () { $.getJSON("/Dashboard/GetData/", function (data) { var chart = new CanvasJS.Chart("chartContainer", { theme: "theme2",//theme1 title: { text: "CanvasJS Charts in ASP.Net MVC using AJAX & JSON" }, data: [ { // Change type to "bar", "splineArea", "area", "spline", "pie",etc. type: "column", dataPoints: data } ] }); chart.render(); }); }); </script> <body> <div id="chartContainer" style="height: 300px; width: 100%;"></div> </body>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)