Chartjs-Charts not showing on ASP.NET MVC page

1👍

Two changes needed:

Serialize the data into JSON in the controller:

using System.Web.Script.Serialization;

var js = new JavaScriptSerializer();
ViewBag.Value_List = js.Serialize( iData2);
ViewBag.Name_List = js.Serialize(iData);

Remove the extra square brackets in the view:

labels: @Html.Raw(ViewBag.Name_List),

data: @Html.Raw(ViewBag.Value_List)

You need to create “drop in” JavaScript to represent the data.

labels: ["555","666","777"] ,

data: ["Sam","Alex","Michael"] 

Leave a comment