i want chart on Results Page. i have a class Results
using System;
namespace PersonalArea.DAL.Models
{
public class Result
{
public string Id { get; set; }
public string PatientId { get; set; }
public string GameName { get; set; }
public string Time { get; set; }
public int Score { get; set; }
public int Level { get; set; }
public DateTime FirstEnter { get; set; }
public DateTime DateEnter { get; set; }
public DateTime DateExit { get; set; }
public string DifficultLevel { get; set; }
public virtual Patient Patient { get; set; }
}
}
In PatientController has a some method
[HttpGet]
public async Task<IActionResult> Results(string id)
{
if (string.IsNullOrEmpty(id))
{
return NotFound();
}
Patient patient = await _userManager.FindByIdAsync(id) as Patient;
if (patient == null)
{
return NotFound();
}
IQueryable<IGrouping<string, Result>> results = _context.Results.Where(x => x.PatientId == id).GroupBy(z => z.GameName);
return View(results);
}
And in Results.cshtml have a some code:
@model IQueryable<IGrouping<string, PersonalArea.DAL.Models.Result>>
@inject IJsonHelper Json;
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<title>Index</title>
</head>
<body>
<div id="chartContainer"></div>
<script type="text/javascript">
var model = @Html.Raw(Json.Serialize(Model));
var datapoints = [];
// build an array of objects
$.each(model, function(index, item) {
datapoints.push({ x: new Date(item.DateEnd), y: item.scores });
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme2",
animationEnabled: true,
title: {
text: "Simple Column Chart in ASP.NET MVC"
},
subtitles: [
{ text: "Try Resizing the Browser" }
],
data: [
{
type: "column", //change type to bar, line, area, pie, etc
dataPoints: datapoints
/*[
{ x: 10, y: 71 },
{ x: 20, y: 55 },
{ x: 30, y: 50 },
{ x: 40, y: 65 },
{ x: 50, y: 95 },
{ x: 60, y: 68 },
{ x: 70, y: 28 },
{ x: 80, y: 34 },
{ x: 90, y: 14 }
]*/
//Uncomment below line to add data coming from the controller.
//dataPoints: @Html.Raw(ViewBag.DataPoints),
}
]
});
chart.render();
};
</script>
</body>
</html>
But system have error:
An unhandled exception occurred while processing the request.
JsonSerializationException: Self referencing loop detected with type 'PersonalArea.DAL.Models.Result'. Path '[0][0].patient.results'.
Please, help my resolve this error