Ben Ben - 7 months ago 63
ASP.NET (C#) Question

How to set the BackImage of a ChartArea at run time?

Anyone know why the ChartArea.BackImage is a property of type string?
Would it not have made more sense for this to have been a property of type Image?

Or to put it another way, how can I set the background image of a ChartArea to an image generated at run-time (e.g. from GraphicPath objects)?

Suggestions are welcome, thanks.


As MSDN states here: ChartArea.BackImage Property. The BackImage property is a string value that represents the URL of an image file.

So to provide an image created dynamically you will need to create your image (checkout the following article about using objects from the System.Drawing namespace to achieve this): Dynamic Image Generation with ASP.Net

Which you can either:

1 - Store to the file system.


2 - Setup an HttpHandler to serve it dynamically.

See: Using HttpHandlers to serve image files

Either way you would need to set the path to the image like so:

Chart.ChartAreas[0].BackImage = imagePath;

Hope this helps.