5

I'm using Microsoft's Chart control to plot some series, but if I have no data, I want to display "No Data Series" on the area where the plot would be.

Like this:

similarpic http://blogs.telerik.com/Libraries/MetaBlogLib/WindowsLiveWriter-CreatingabasicChart_D20D-image_thumb.sflb

I have a hunch it has something to do with manually drawing some text onto the image, but I don't know where to start. Anyone?

Jeff Meatball Yang
  • 37,839
  • 27
  • 91
  • 125
  • Check out this answer. http://stackoverflow.com/questions/14051948/how-to-display-error-message-into-chart-in-asp-chart-controls – Stuart Nov 28 '16 at 12:27

1 Answers1

2

You can create a post-paint event handler where you can paint your stuff:

mychart.PostPaint += new EventHandler<ChartPaintEventArgs>(PostPaintEventHandler);
...
static void PostPaintEventHandler(object sender, ChartPaintEventArgs e)
{
  //sender here is the chart... you can use that too.
  //use e.ChartGraphics object to paint something
  e.ChartGraphics.DrawString(...);
}

Use freeware ILSpy to look inside the MSChart dll. There are several overloads of Graphics.DrawString method. Use the one which fits best for you.

Hope this helps.

scrat.squirrel
  • 3,607
  • 26
  • 31