I have most of this figured out, but I am wondering if I need to return a partial page view or just an image.
So, the way drill-down charts need to be implemented under MVC can be seen at: http://geekswithblogs.net/DougLampe/archive/2011/01/23/charts-in-asp.net-mvc-2-with-drill-down.aspx
The key point to make here is that we are leveraging the URL property of a series to navigate 'down a level' on the chart.
public ActionResult HistoricalChartMap(int reportID)
{
HistoricalChartData chartData = new HistoricalChartData(reportID, string.Format("Chart_{0}", Guid.NewGuid().ToString().Replace('-', 'a')));
LineChart chart = new LineChart(chartData);
foreach (Series series in chart.Series)
{
string postBackValue = series.PostBackValue;
series.Url = string.Format("../Chart/HistoricalDrillDown?ReportID={0}&PostBackValue={1}", reportID, postBackValue);
}
//Must call SaveImage before GetHtmlImageMap
var imgStream = new MemoryStream();
chart.SaveImage(imgStream);
imgStream.Seek(0, SeekOrigin.Begin);
string sessionKey = string.Format("HistoricalReport: {0}", reportID);
Session[sessionKey] = chart;
// Return the contents of the Stream to the client
return Content(chart.GetHtmlImageMap("HistoricalChartMap"));
}
Note that the URL points to a method of my ChartController:
public ActionResult HistoricalDrillDown(int reportID, string postBackValue)
{
string sessionKey = string.Format("HistoricalReport: {0}", reportID);
LineChart lineChart = (LineChart)Session[sessionKey];
lineChart.DrillChart(postBackValue);
var imgStream = new MemoryStream();
lineChart.SaveImage(imgStream);
imgStream.Seek(0, SeekOrigin.Begin);
// Return the contents of the Stream to the client
return File(imgStream, "image/png");
}
HistoricalDrillDown returns the new ChartImage that I would like to display in my partial view, but I am dropping the ball at this point. How should I go about replacing my current chart image with the image returned? Currently, I am just directed to a new page that has just the chart image on it.
My partial view's markup is like so:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div id="HistoricalChartDialog">
<div id="ChartConfigurators">
<label for="ReportSelector">Historical Chart: </label>
<select id="ReportSelector" name="ReportSelector"></select>
<div id="ToggleLegendWrapper">
<label for="ToggleLegend">Toggle Legend</label>
<input type="checkbox" id="ToggleLegend" name="ToggleLegend" />
</div>
</div>
<img id="HistoricalChart" src="" alt="" usemap="#HistoricalChartMap" />
</div>
Note the img tag in the middle of this partial view. I would like to update the img's SRC attribute after a user has followed the URL to HistoricalDrillDown.
Taking suggestions. :)
Kind regards.
I opted to do this:
foreach (Series series in lineChart.Series)
{
series.Url = string.Format("javascript: DrillChart('{0}')", series.PostBackValue);
}
and then handled the logic client-side for replacing the image.