Perozzo Perozzo - 1 year ago 93
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?

Answer Source

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));

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download