Well, I am returning a list of and sending to View
. You need to implement this using a graph with Chart.js
.
I have the Country class:
[Table("Pais")]
public class Pais
{
[Key]
public Guid PaisId { get; set; }
[Required]
public String Nome { get; set; }
public virtual ICollection<FertilidadePorAno> FertilidadePorAno { get; set; }
}
The class FertilityPorn :
[Table("FertilidadePorAno")]
public class FertilidadePorAno
{
[Key]
public Guid FertilidadePorAnoId { get; set; }
public Guid PaisId { get; set; }
[Required]
public int Ano { get; set; }
[Required]
public decimal Valor { get; set; }
public virtual Pais Pais { get; set; }
}
And a ParentFertille associative class:
[Table("PaisFertilidadePorAno")]
public class PaisFertilidadePorAno
{
public Guid PaisFertilidadePorAnoId { get; set; }
public string Nome { get; set; }
public int Ano { get; set; }
public double Valor { get; set; }
}
My controller
looking for the data in the Bank:
public async Task<ActionResult> Relatorio(Guid id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var entries = db.Database.Connection
.Query<PaisFertilidadePorAno>(@"SELECT p.Nome, f.Ano, f.Valor from Pais As p
inner join FertilidadePorAno as f
on f.PaisId = p.PaisId
where p.PaisId = @id
order by f.Ano", new { Ano = (int?)null, Id = id });
return View(entries);
}
Return the data to View
which is currently like this:
@model IEnumerable<TaxaDeFertilidade.Models.PaisFertilidadePorAno>
@{
ViewBag.Title = "Relatorio";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Relatorio</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Nome)
</th>
<th>
@Html.DisplayNameFor(model => model.Ano)
</th>
<th>
@Html.DisplayNameFor(model => model.Valor)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Nome)
</td>
<td>
@Html.DisplayFor(modelItem => item.Ano)
</td>
<td>
@Html.DisplayFor(modelItem => item.Valor)
</td>
</tr>
}
</table>
However, I need to create a chart.js
chart with this information coming from the Bank that are the name of the Country , Year and the Fertility Rate < in relation to that
year. How do I do this in View
?