Pre loader

How do I move and resize annotations on chart zoom and pan?

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums


I have two types of annotations on my chart that I add at run time.

o A vertical line annotation. I need to be able to scale this so it maintains a fixed pixel height rather than a fixed y-scale height on zoom.

o A text annotation. I need to be able to change the location on the y-axis so that the text is always visible when it’s within range on the x-axis.

I’ve looked at various ways of handling these, and they all wind up forcing a redraw. Is there a way of scaling/moving annotations on zoom that won’t force a redraw?

  • You must to post comments

Hi there!

Thanks for the screenshots! OK, regarding vertical lines, you could extend VerticalLineAnnotation in such a way:

    public class VerticalLineAnnotationEx: VerticalLineAnnotation

        public new double Height
            get { return (double)GetValue(HeightProperty); }
            set { SetValue(HeightProperty, value); }

        // Using a DependencyProperty as the backing store for Height.  This enables animation, styling, binding, etc...
        public static readonly new DependencyProperty HeightProperty =
            DependencyProperty.Register("Height", typeof(double), typeof(VerticalLineAnnotationEx), new PropertyMetadata(0d));

        protected override void PlaceAnnotation(AnnotationCoordinates coordinates)

            base.Height = Height;

..and usage in Xaml:

                <annotationsWithFixedHeight:VerticalLineAnnotationEx X1="4.8" Y1="0" Y2="0" VerticalAlignment="Center" Height="20"/>

Notice, you need to set Y1 and Y2 to same value and VerticalAlignment to “Center”.

Regarding TextAnnotations, you need to change their placement manually, in the XAxis.VisibleRangeChanged event handler. For each TextAnnotation, check if it is inside current viewport and change Y1 coordinate correspondingly. Something like that(pseudo code):

var annotationEnd = annotation.Y1 + YAxis.GetDataValue(annotation.ActualHeight);
if(IsInViewport(annotation.Y1, annotationEnd))
annotation.Y1 = [new coordinate];


bool IsInViewport(y1, y2)
return y1 >= YAxis.VisibleRange.Min && y2 <= YAxis.VisibleRange.Max;

Please, feel free to ask if you need further assistance with this!

Best regards,

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies