Reputation: 55
I'm trying to test charting functionality in my C#.NET 4.0 MVC application following this guide.
Here is my View code:
@{
Layout = null;
}
@{
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Employees")
.AddSeries(chartType: "column",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: new[] { "2", "6", "4", "5", "3" })
.Write();
}
When I run the application it just gives me a bunch of ASCII characters:
JFIF``C $.' ",#(7),01444'9=82<.342C 2!!22222222222222222222222222222222222222222222222222X" }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B#3R$4&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz? ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( +LL1VFwc@uQUn:j(((((((((((((((((((((((((((((((((((( P';ա2nd4x Iv {ͿKmv#Y@P;kݖ ^N7f+ =huE@co qG(ܒI)V0AA}{6ND!\CW 3Q 3Q}vNZ4 bcy?xZfFtfoNjG/CxZf9k2hhEş" c-Fg:CjҨV NH1yEsl?}"AEsl?}"AEsl?}"
Any thoughts on how to troubleshoot/proceed? I'm just looking for a simple bar graph solution. Thanks!
Upvotes: 0
Views: 199
Reputation: 21
OK, I have the same problem, and I solve using another logic, and works fine:
I remove de partial view (cshtml) and change the signature on Controller to return a Chart type:
public Chart GetGrafico(int dias, int idDepartamento, int idPgto)
{
try
{
int idEmpresa = login.GetUsuario(System.Web.HttpContext.Current.User.Identity.Name).IdEmpresa;
DateTime inicial = DateTime.Today.Date;
DateTime final = inicial.AddDays(dias);
var grafico = service.GetGrafico(inicial, final, idEmpresa, idDepartamento, idPgto);
Chart myChart = new Chart(800, 600)
.AddTitle("Vencimentos futuros")
.AddSeries(
name: "Vencimentos",
xValue: grafico.Select(x => x.Dia).ToArray(),
yValues: grafico.Select(x => x.Valor).ToArray()).Write();
return myChart;
}
catch (Exception)
{
throw;
}
}
Then in the Index.cshtml I just add a image tag:
<img id="img" />
<script type="text/javascript">
$('#gerarGrafico').click(function () {
$('#img').attr('src', '/Erp/Grafico/GetGrafico?dias=30&idDepartamento=0&idPgto=0');
});
So now when a click in the button, the jQuery function just set the attr src of image, it works fine.
Upvotes: 1