Greetings!
I am currently in the process of building a dashboard that includes a Morris chart. The dashboard is built using ASP MVC.
Using JavaScript, I invoke a function in my controller to retrieve data.
$.get('@Url.Action("Diagram")', function (result) {
console.log(result) #Contains the correct information
Morris.Line({
element: 'morris-area-chart',
data: result,
xkey: 'period',
ykeys: ['ColliAantal'],
labels: ['Colli aantal'],
pointSize: 1.5,
hideHover: 'auto',
resize: true
});
"Result" holds the necessary JSON data for the chart.
The code displayed here pertains to the controller. The scoreboard has already been defined and contains the correct data.
try
{
List<ChartData> chartData = new List<ChartData>();
foreach (Scorebord item in scorebord.Take(100))
{
chartData.Add(new ChartData(item.ColliQty, item.Datum));
}
var json = JsonConvert.SerializeObject(chartData);
return Json(json, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return null;
}
An interesting observation is that when I manually copy and paste the data returned by the controller during debugging directly into the JavaScript as data, it starts working suddenly!
I am hopeful that someone can assist me with this seemingly simple issue. Thank you!