Perozzo Perozzo - 20 days ago 5
ASP.NET (C#) Question

Populating morris chart in ASP.NET MVC

I'm having a problem when trying to populate morris chart dynamically.

This is the JSON string:

[{"Name":"Paul Walker","ExamQuantity":35},{"Name":"Vin Diesel","ExamQuantity":1}]

Then in javascript I do this:

var model = @Html.Raw(Json.Serialize(ViewBag.TeacherExams));

new Morris.Bar({
element: 'chartTeacherExams',
data: model,
xkey: 'Name',
ykeys: ['ExamQuantity'],
labels: ['Quantidade']

But when the chart loads, I get this image:

enter image description here

Any ideas what I am doing wrong?


Please try change data:model using your json array.

In your case, use: data:[{"Name":"Paul Walker","ExamQuantity":35},{"Name":"Vin Diesel","ExamQuantity":1}].Array is already in JSON format.

You do not need this line: var model = @Html.Raw(Json.Serialize(ViewBag.TeacherExams));