I'm trying to bind data from my Razor Code-behind page to my .cshtml file, to load the Kendo chart. What I'm trying to achieve is have the male and female counts in the bar with the X-axis being the admission term and the Y-axis being the count of Male and female.
currently, the data does not bind to the chart.
Please find What I have attempted below.
public async Task<IActionResult> OnGetStudentMDProgramAll()
{
AllStudents = await _studentService.GetStudentProgramsAll();
foreach (var student in AllStudents)
{
StudentBreakdownReportModel std_brk_rpt_mdl = new StudentBreakdownReportModel();
std_brk_rpt_mdl.AdmissionTerm = student.AdmissionTerm;
std_brk_rpt_mdl.Female = AllStudents.Where(ad => ad.Student.Gender == "F").ToList().Count().ToString();
std_brk_rpt_mdl.Male = AllStudents.Where(ad => ad.Student.Gender == "M").ToList().Count().ToString();
std_brk_rpt_mdl.FemaleResidency_SC = AllStudents.Where(ad => ad.Student.Gender == "F" && ad.Student.Code == "SC").ToList().Count().ToString();
std_brk_rpt_mdl.FemaleResidency_SPR = AllStudents.Where(ad => ad.Student.Gender == "F" && ad.Student.Code == "SPR").ToList().Count().ToString();
std_brk_rpt_mdl.FemaleResidency_INTL = AllStudents.Where(ad => ad.Student.Gender == "F" && ad.Student.Code == "INTL").ToList().Count().ToString();
std_brk_rpt_mdl.MaleResidency_SC = AllStudents.Where(ad => ad.Student.Gender == "M" && ad.Student.Code == "SC").ToList().Count().ToString();
std_brk_rpt_mdl.MaleResidency_SPR = AllStudents.Where(ad => ad.Student.Gender == "M" && ad.Student.Code == "SPR").ToList().Count().ToString();
std_brk_rpt_mdl.MaleResidency_INTL = AllStudents.Where(ad => ad.Student.Gender == "M" && ad.Student.Code == "INTL").ToList().Count().ToString();
Report.Add(std_brk_rpt_mdl);
}
return new JsonResult(Report, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
}
Please find the Razor page Code below
@(Html.Kendo().Chart<Models.StudentBreakdownReportModel>()
.Name("mdchart")
.Title("Student Intake by Residency and Gender for MD Program")
.Legend(legend => legend
.Position(ChartLegendPosition.Top)
)
.DataSource(ds => ds.Read(read => read.Type(HttpVerbs.Get).Url(Url.Page("StudentBreakdownReport", "StudentMDProgramAll"))))
.Series(series =>
{
series.Column(model => model.Female).Name("Female").CategoryField("AdmissionTerm");
series.Column(model => model.Male).Name("Male").CategoryField("AdmissionTerm");
})
.SeriesColors(
"#cd1533", "#009bd7"
)
.CategoryAxis(axis => axis
.Labels(labels => labels.Rotation(-90))
.MajorGridLines(lines => lines.Visible(false))
)
.ValueAxis(axis => axis.Numeric()
.Line(line => line.Visible(false))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0:N0}")
)
)