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?
- pray asked 11 years ago
- You must login 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.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
- Yuriy Zadereckiy answered 11 years ago
- You must login to post comments
Please login first to submit.