简体   繁体   中英

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:

在此处输入图片说明

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.

The mistake is in this line: var model = @Html.Raw(Json.Serialize(ViewBag.TeacherExams));

Json.Serialize turns JSON object to JSON string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM