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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

1
0

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
0
0

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.PlaceAnnotation(coordinates);

            base.Height = Height;
        }
    }

..and usage in Xaml:

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

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,
Yuriy

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.