Reputation: 1740
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?
Upvotes: 1
Views: 927
Reputation: 598
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.
Upvotes: 1