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.
Or
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.
Solution using NamedImage
var chartBackImage = new Bitmap(1,1); //some bmp
chart1.Images.Add(new NamedImage("GiveSomeName", chartBackImage));
chart1.Areas[0].BackImage = Images[0].Name;
chart1.Areas[0].BackImageWrapMode = ChartImageWrapMode.Scaled; //extra
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With