ASP.NET Charting - MapAreas null when returning chart as binary data
My objective: return coordinates and shapes so that I can roll my own custom hover text to a .NET Charting image. This would be no problem if I were using the ASP.NET control (which renders both an image tag and an HTML <map>
tag; however, I'm in the MVC world so I'm returning the chart as a binary image. Here's the gist:
public virtual FileStreamResult Chart()
{
//Set up chart
Chart Chart1 = new Chart();
Chart1.RenderType = RenderType.ImageTag;
Chart1.ChartAreas.Add(new Ch开发者_JS百科artArea("First"));
//Add some lovely data
Series s = new Series();
s.Name = "Tasks";
s.Points.AddXY("Task 1", 5, 8);
s.ChartArea = "First";
s.ChartType = SeriesChartType.RangeBar;
//Add a tooltip - This **should** make the MapAreas collection populate.
s.ToolTip = "Hello World";
Chart1.Series.Add(s);
if (Chart1.MapAreas.Count == 0)
CryRiver(); //Always executed. :*(
//Output image as FileStreamResult
//...
}
The Problem: No matter what I do, I cannot get the MapAreas
collection to contain anything. I believe this to be because the coordinates don't get populated until the image actually renders.
How do I get at the coordinates of the map areas for the charted data when rendering an image as binary?
Thanks!
Found an answer; not sure if it's the best one.
One must call Chart1.RenderControl();
before the Chart1.MapAreas gets populated.
精彩评论