Home forums Using CanvasJS Display Chart using JSON data in ASP MVC Reply To: Display Chart using JSON data in ASP MVC

#6459

Anjali
Participant

Hi,
You basically need to transform your JSON data into a format supported by CanvasJS.

Here is an example :

var dataPoints =[];
$.getJSON(“/Dashboard/GetData/”,function(data) {
for(var i=0; i<= data.length-1; i++) {
dataPoints.push({label:data[i].Title,y:parseInt(data[i].Credits)});
}
var chart = new CanvasJS.Chart(“chartContainer”, {
theme: “theme2”,
title: {
text: “CanvasJS Charts in ASP.Net MVC using AJAX & JSON”
},
data: [
{
type: “column”,
dataPoints: dataPoints
}
]
});
chart.render();
});