I downloaded the code and am following the sample Guy from Queensland
How can I refresh the chart when I click Refresh?
The following code returns the PNG in binary.
<input type="submit" value="Refresh" id="refreshIssueHistory" />
<div id="theImageIssueHistory">
<% Html.RenderPartial("~/Views/Issue/Charts/IssueHistoryImg.ascx"); %></div>
<script type="text/javascript">
$(document).ready(function() {
$("#refreshIssueHistory").click(function() {
RefreshImage();
});
});
function RefreshImage() {
$.ajax({
type: "POST",
url: "/Issue/" + "GetIssuesHistoryChart",
dataType: "html",
data: {
projectId: 2// changing ID here to see if the image changes
},
success: function(v) {
RefreshHistoryImage(v);
},
error: function(v, x, w) {
//Error
}
});
}
function RefreshHistoryImage(v) {
$('div#theImageIssueHistory').load('/Issue/GetIssuesHistoryChart', { projectId: 2 },
function(html) {
$('div#theImageIssueHistory')[0].value = html;
});
}
</script>
IssueHistoryImg.ascx
<img src="/Issue/GetIssuesHistoryChart" alt="My Issues" />
Controller
public FileResult GetIssuesHistoryChart(int? projectId)
{
...
System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
Chart1.SaveImage(imageStream, ChartImageFormat.Png);
return new FileResult("Yo.png", "image/png", imageStream.ToArray());
}
The controller method works fine, only when I click the refresh button that it does not return what I want it to.
It was a challenge, but here is how I did it. The key for me was adding the datetime stamp as part of the AJAX call in refreshChart(). That change defeated any browser or proxy caching that was preventing the chart from updating.
Index.aspx
Site.css
ChartController.cs
Other tools used in the solution (but irrelevant to answer the question):