0

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<.342￿￿C 2!!22222222222222222222222222222222222222222222222222￿￿￿X"￿￿ ￿￿￿}!1AQa"q2￿￿￿#B￿￿R￿$3br￿ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿ ￿￿￿w!1AQaq"2￿B￿￿￿￿#3R￿￿$4￿&'()56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿￿?￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ (￿￿ +￿￿￿￿L￿L￿1V￿￿Fwc￿￿￿@u￿QU￿￿n￿￿￿￿￿￿:￿j￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿(￿￿￿￿ ￿P￿￿￿￿￿'￿;￿￿ա￿2￿￿n￿d￿￿￿￿4￿x ￿￿￿￿￿I￿￿v {Ϳ￿K￿￿￿mv￿￿#￿Y￿@P;￿kݖ ^N7f￿+￿￿ ￿=￿h￿u￿E@c￿￿￿o ￿￿qG￿￿￿(￿￿￿ܒI￿)V￿0A￿￿￿￿￿￿￿￿￿A}￿￿{￿￿6￿￿￿￿ND￿￿￿!￿\￿￿￿C￿W￿ 3￿￿￿Q￿ 3￿￿￿Q￿￿}v￿￿￿N񦥭￿￿￿￿Z4￿ ￿￿bc￿￿￿y￿?￿x￿￿Z￿f￿￿￿Ft￿￿foN￿jG￿/C￿￿￿￿￿x￿￿Z￿f￿￿￿￿9￿￿￿k2΂￿￿￿h￿￿h￿￿￿￿￿E￿￿￿￿￿ş￿"￿￿￿￿￿￿￿￿￿￿￿￿ c￿-Fg:￿CjҨV￿￿ ￿NH￿1￿yEs￿l￿￿?￿￿}￿￿￿￿"￿AEs￿l￿￿?￿￿}￿￿￿￿"￿AEs￿l￿￿?￿￿}￿￿￿￿"￿

Any thoughts on how to troubleshoot/proceed? I'm just looking for a simple bar graph solution. Thanks!

3
  • Nothing wrong with your posted code. Commented Mar 17, 2016 at 21:24
  • Yeah, the code is good which is why I'm puzzled as to why it's spewing out the ASCII garbage instead of rendering the simple graph? At a loss Commented Mar 17, 2016 at 21:30
  • Note that the tutorial you're following, which works perfectly well, is for a Web Site project template, not MVC. Each project template adds their own specific assemblies, folder/file structure, etc, so don't expect things to be fully interchangeable. Commented Mar 18, 2016 at 12:51

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.