Although there are a lot of questions, I tried everything and every one of the examples but I can not make what I need work. First I ask the database to look for receipts issued during the year to be grouped by months: View where I choose the year
<form asp-action="GraficarPorPeriodo" method="post">
<div class="form-group form-inline">
<div class="col-md-4">
<label>Seleccione Período</label>
<select class="form-control input-sm" asp-items="ViewBag.años" id="periodo" name="periodo"></select>
</div>
</div>
<br />
<div class="form-group">
<input class="btn btn-info" value="Graficar" type="submit" />
</div>
Then I execute the query:
public IActionResult GraficarPorPeriodo(string periodo)
{
var cuenta = (from r in _context.Recibos
where r.Tipo == "Recibo"
&& r.Fecha.Value.Year >= Convert.ToInt32(periodo)
&& r.Fecha.Value.Year <= Convert.ToInt32(periodo)
select r).GroupBy(g => g.Fecha.Value.Month).Select(x => new
{
Cuenta = x.Count()
});
List<int> Lista = new List<int>();
foreach (var item in cuenta)
{
Lista.Add(item.Cuenta);
//Lista.Add(string.Concat(","));
//ViewData["cuenta"] = Lista;
}
return View(Lista);
}
And finally in the View I have the following:
$(document).ready(function () {
$.getJSON("/Recibos/GraficarPorPeriodo", function (data) {
Highcharts.chart('chart', {
chart: {
type: 'column'
},
title: {
text: 'Recibos'
},
xAxis: {
categories: [
'Jun',
'Jul',
'Ago',
'Sep',
'Oct',
'Nov',
'Dic'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Cantidad'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Recibos',
data: data
}]
});
});
});
With this I only get that the view has no graph. Try changing with return Json(Lista)
and just show me the JSON results
[1,9,3]
Any advice? Thank you very much from now!