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

0
0

Here we use a TextAnnotation as follows

 var textAnnotation = new TextAnnotation
                                 {
                                     Name = seriesAnnotationParameter.Name,
                                     Text = seriesAnnotationParameter.Text,
                                     ToolTip = seriesAnnotationParameter.ToolTip,
                                     XAxisId = XAxisId,
                                     YAxisId = YAxisId,
                                     X1 = seriesAnnotationParameter.X1,
                                     Y1 = seriesAnnotationParameter.Y1,
                                     HorizontalAnchorPoint = HorizontalAnchorPoint.Center,
                                     VerticalAnchorPoint = VerticalAnchorPoint.Center,
                                     TextAlignment = TextAlignment.Center,
                                     Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x00, 0x00)),
                                     Opacity = 0.5,
                                     BorderThickness = new Thickness(1),
                                     CornerRadius = new CornerRadius(1),
                                     IsEditable = false
                                 };

It works perfectly all-rite when you attach it to the chart the first time as in attached image TextAnnotation_Good.png. However, after zooming in or zooming out, the annotation is resized to undesirable sizes as in attached image TextAnnotation_Bad.png.

How to make TextAnnotation to resize itself based on the size of text inside it ?

This is a very special TextAnnotation centered around a x,y coordinate. There is never X2,Y2 for this use case.

Images
  • You must to post comments
0
0

Hi Jerome,

The TextAnnotation only ever listens to X1, Y1 properties, and automatically calculates its size based on the text within it.

I haven’t tested this but I have something you can try out. Perhaps you can override this by setting TextAnnotation.Width, TextAnnotation.Height explicitly, e.g. during a layout pass, measure the contents and set the TextAnnotation size.

Alternatively, it is possible to set the BoxAnnotation.ControlTemplate to contain any UI, for instance, you could put a ViewBox and TextLabel in there. BoxAnnotation allows for finer control over size base on X1,Y1,X2,Y2.

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.