3

When using Fastlines, annotations do not show up in the Chart (Whatever the nature of the annotation) This is very annoying and I've read through the MSDN on the subject, there is no trace of such a restriction. If anybody can confirm that freak/buggy behavior and offer some workaround, he's very welcome.
The only ugly trick i've found is to plot a duplicate transparent line and anchor the annotations to its points.. At least, I hope this post will avoid other developers screwing their nights on this.

The more I use MS Chart Control (Ex-Dundas) the more I'm getting used to dirty hacks like these.
Just one among too many night/sleep/life spoiler for developers.

EDIT :
To asnwer a code sample request :

  System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
  series1.ChartArea = myChartArea.Name;
  series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
  series1.Legend = "Default";
  series1.Name = "Series1";
  this.chart.Series.Add(series1);

  Random random = new Random();
  for (int pointIndex = 0; pointIndex < 10; pointIndex++)
   series1.Points.AddXY(DateTime.Now.AddHours(pointIndex), random.Next(5, 60));

  RectangleAnnotation annotation = new RectangleAnnotation();
  annotation.AnchorDataPoint = series1.Points[1];
  annotation.Text = "Just Won't Work";
  annotation.ForeColor = Color.Black;
  annotation.Font = new Font("Arial", 12); ;
  annotation.LineWidth = 2;

  chart.Annotations.Add(annotation);
Community
  • 1
  • 1
Mehdi LAMRANI
  • 11,289
  • 14
  • 88
  • 130

2 Answers2

4

Yes, I tested it and you're right...

Also, quoting from this MSDN link:

The FastLine chart type is a variation of the Line chart that significantly reduces the drawing time of a series that contains a very large number of data points. Use this chart in situations where very large data sets are used and rendering speed is critical.

Some charting features are omitted from the FastLine chart to improve performance. The features omitted include control of point level visual attributes, markers, data point labels, and shadows.

If you really need Annotations, I think you should switch to Line Chart...

digEmAll
  • 56,430
  • 9
  • 115
  • 140
  • "Some charting features are omitted" Well, Bravo to MS for the exhaustive precision. That's too bad and disappointing, cause I got both needs : I do have Millions of points to plot, AND i want to Plot some signals when they occur. Anyway, i'll make do with it (and switch back to Zedgraph when I have time :-) ) – Mehdi LAMRANI Mar 09 '11 at 12:07
2

One Workaround Solution I've implemented to meet my specific needs is to put annotations into an extra Line Series having BorderWidth set to 0 so the line does not display, containing only the points that I want to be annotated.

So I have 2 series, one with SeriesChartType "FastLine", and another one (invisible) with SeriesChartType "Line" with some points from the first series where I want my annotations (visible).

Hacky but it works and do not blow performance if you do not haev thousands of annotations.

Mehdi LAMRANI
  • 11,289
  • 14
  • 88
  • 130
  • 1
    You can also try to hide the `Series` using `Series.Enabled`, and to be even faster, create a point series instead of a line one (I guess it will need less computation to draw points instead of lines) – digEmAll Mar 09 '11 at 14:11
  • Thank You diGGy diGGy, Good Point. I feel less lonely in the rickety World of MS Chart Control :-) – Mehdi LAMRANI Mar 09 '11 at 15:32