SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and now iOS Charting & Android Chart Components


Using MVVM, I have an AnnotationCollection databound to the SciChartSurface.Annotations. Individual LineAnnotations are added to the collection as the application code runs.

If annotations are added while the chart is displayed, they are all drawn correctly.

However, if the chart page is reloaded (say, the user navigates to a different page and then returns to the chart page), the annotations do not always redraw. If the annotations have AnnotationCanvas set to default (AnnotationCanvas.AboveChart, I believe) they redraw correctly about 50% of the time. If the annotations’ AnnotationCanvas is set to AnnotationCanvas.XAxis, they never redraw.

All the annotations still exist in the ObservableCollection in all these cases, so they shouldn’t need to be re-created.

Is this a bug in SciChart or is there something I may be doing wrong with the annotations?
(There is only one X-Axis so no axisID is necessary.)

LineAnnotation lAnno = new LineAnnotation();
lAnno.CoordinateMode = AnnotationCoordinateMode.RelativeY;
lAnno.Y1 = 0.0;
lAnno.X1 = DataPoints;
lAnno.Y2 = 1.0;
lAnno.X2 = DataPoints;
lAnno.YAxisId = "Counts";
lAnno.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(255, 255, 255));
lAnno.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(96, 255, 0, 0));
lAnno.StrokeThickness = 2;
lAnno.AnnotationCanvas = AnnotationCanvas.XAxis;

  • You must to post comments

Hi Matthew,

Annotations cannot be attached to more than one parent element (This is a WPF restriction where each FrameworkElement is expected to have one parent).

When you attach an Annotation to a SciChartSurface then Annotation.Parent will be set to the canvas on the SciChartSurface.

When you fire-up another chart and attach the same annotations to another chart, they will still be attached to the previous chart, hence the issue you are seeing.

My recommendation is to do one of the following three options:

  1. If only one chart is shown at a time, when closing a chart you can call SciChartSurface.Annotations.Clear(). This will detach all Annotations from that SciChartSurface

  2. Or, if multiple charts are shown, then you will need to recreate annotations on each chart surface created

    2.a A good way to do this is to use an MVVM technique to create annotations and only manipulate annotation ViewModels. For more discussion on this topic, see here

Best regards,

  • Andrew
    Hi Matthew, it should work (I checked the code). If not, possibly a bug. I would recommend creating new annotations then (2, or 2a) and we will log a bug for investigation at some point.
  • Matthew Becker
    I now have also tried re-creating the entire AnnotationCollection along with all the Annotations within it, based on the data in the old annotations, when the chart is re-created, but the new AnnotationCollection.ParentSurface never gets set to the new chart instance either.
  • Andrew
    Maybe its time to zip up your source code (or subset of to reproduce the problem) and email it to us? .. :)
  • Matthew Becker
    I ended up just keeping the raw data for the annotations persistent and moving the actual AnnotationCollection to the viewmodel, so it is recreated each time the user returns to graph. It does make me wonder though, why annotations would give me this issue, but the DataSeries seem to work properly in a recreated chart as-is.
  • Andrew
    I’m glad you got it sorted out Matthew! If you need further help, feel free to open a new forum post, or contact the support desk. Best regards, Andrew
Showing 1 result
Your Answer

Please first to submit.