Search code examples
chartscdnmschartcookielesssystem.web.ui.webcontrols

How to serve System.Web.UI.DataVisualization chart images from different domain?


I have a set of System.Web.UI.DataVisualization charts (ASP.NET 4.0) working great and saving the files to disk. No problems and works great.

The challenge is that I am serving all of my static image and assets from a cookieless domain -- and eventually maybe from a CDN -- and unfortunately, the chart's IMG SRC is always relative. I can't seem to find a way to override that so that I can specify the root domain of the static asset server.

Some possible workarounds I haven't tried yet are:

  • Progamatically generate the charts and manually add an image control to the page
  • URL rewrite any requests for images (extra server hit, may not work)
  • Search and replace the SRC manually before markup is sent to browser (ugh)

Are there any other possibilities I'm not aware/thinking of? Thanks!


Solution

  • To answer my own question, the first bullet of programatically generating the charts (vs having the control markup in the HTML) and adding a control to the page manually seems to work just fine.

    It removes the ability to style things in the markup though, so any other ideas are welcome.

    Edit: I decided to leave the styling markup and programatically hide the chart control and add in the image control separately. Works great!

    Edit: There is one caveat to my solution of adding the image control separately -- if you used the tooltips for each datapoint, they will no longer work once you implement this change since they are generated by the control itself.