1

I have a situation where in I need to show a chart in MVC3 view. Till now I have done the following in my controller

public ActionResult MyChart()
        {
            var bytes = new Chart(width: 400, height: 200)
                .AddSeries(
                    chartType: "bar",
                    xValue: new[] {"Math", "English", "Computer", "Urdu"},
                    yValues: new[] {"60", "70", "68", "88"})
                .GetBytes("png");
            return File(bytes, "image/png");
        }

in my Jquery file

function getChart() {
    $.ajax({
        url: ('/Home/MyChart'),
        type: 'GET',
        cache: false,
        success: function (result) {
            alert(result.length);
            $('#BottomGrid').html(result);
        },
        error: function () { alert("error"); }
    });
    }

and in my view I am simply calling the getChart() method. my view is an .aspx view and bottomgrid is a div on the view where I need to show the chart.

Running the above code in IE gives me a png sign and in firefox it shows me special characters.

Any Idea where am I going wrong?

1 Answer 1

1

Edit your "getChart()" function :

 success: function (result) {
        alert(result.length);
        $('#BottomGrid').append('<img id="myChart" />');
        $('#myChart').attr("src", "/Home/MyChart")
    }

but i don't think it's an ideal solution,because it request the image twice , the first one when you do ajax (it needs a way to render the returned text as image),the second one when the browser parse "img" tag.

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

1 Comment

Actully you can just write these two statments : $('#BottomGrid').append('<img id="myChart" />'); $('#myChart').attr("src", "/Home/MyChart"); instead of doing ajax call. :)

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.