Reputation: 13
I'm trying to create a pie chart in my web application that allows for user interaction (hover, click). The pie chart is rendering fine using the web forms version of the Chart helper. But the image map is always empty:
List<string> items = new List<string>(new string[] {"what", "is", "wrong"});
List<decimal> values = new List<decimal>(new decimal[] { 1, 2, 3 });
Chart myChart = new Chart();
myChart.ChartAreas.Add(new ChartArea());
myChart.Series.Add(new Series("Data") { ChartType = SeriesChartType.Pie });
myChart.Series["Data"].Points.DataBindXY(items, values);
using (MemoryStream stream = new MemoryStream())
{
myChart.SaveImage(stream, ChartImageFormat.Jpeg);
string result = "<img usemap='#myMap' src='" + String.Format("data:image/jpeg;base64,{0}", Convert.ToBase64String(stream.ToArray())) + "' />";
return result + myChart.GetHtmlImageMap("myMap");
}
Resulting image map:
<map name="myMap" id="myMap">
<area shape="rect" coords="0,0,0,0" alt="">
</map>
The MS documentation includes this oh-so-helpful caveat: "If you render the chart as a binary stream, a special technique must be used to implement client-side image maps."
What am I missing? What is the "special technique" that MS apparently wants to keep a secret?
Upvotes: 1
Views: 1080
Reputation: 54433
Things are well-hidden and dispersed, as usual with any incarnation of Chart
controls.
Deducing from this quote:
Chart.IsMapEnabled Property
Remarks;
Setting this property to false will disable image maps. This will occur even under the following circumstances:
The Url, MapAreaAttributes, LabelMapAreaAttributes, LegendMapAreaAttributes or ToolTip property of a chart element is set.
A MapArea object has been added to the MapAreasCollection object.
you need to add a MapArea
to the MapAreas
collection of the Chart
.
More hints can be found with Chart.RenderType
:
Chart.RenderType
Remarks:
The following list describes the three ways in which a chart image can be rendered:
The ImageTag render type causes a temporary file to be saved to disk at the server. The chart is displayed at the client side using an tag, with its SRC attribute set to the URL specified by the ImageLocationproperty.
If the BinaryStreaming render type is specified, there are no temporary image files at the server. Instead, the chart image is sent as a binary stream, and is displayed using an tag with its SRC attribute set to another .aspx page that is responsible for generating the chart image.
A render type of ImageMap causes an image map to be created, but does not result in the display of an actual chart image. This option should only be taken when using an image map that has a render type of BinaryStreaming.
Upvotes: 1