Position annotation relative to chartrow in multiple row chart?

Hi, I would like to position a text annotation using pixels relative to a specific chartrow in a multiple row chart. For example, a chart contains 3 chartrows (each with their own y axis), and I want to position a textannotation 5 pixels below the top edge of the middle chartrow and 10 pixels from the left edge of the chart. There will be additional textannotations immediately below the first one. When the chart resizes, or when the y axis of the chartrow changes visiblerange (zooms), the annotations should keep the same fixed pixel distance. The creation of the textannotations and the positioning should preferably all be done in code behind. Attached is an image showing what I want. How can this be achieved?

Thank you.

Attachment: SnapShot_76_40b9488e.rar

3 Replies

MK Muneesh Kumar G Syncfusion Team October 23, 2018 11:36 AM UTC

Hi Tom, 
 
Greetings from Syncfusion, we have analyzed your requirement and we have achieved this by setting CoordinateUnit as Pixel and update its position in SizeChanged, ZoomChanged, RangeChanged events as per the below code snippet.  
 
Code snippet 
   public MainWindow() 
        { 
            InitializeComponent(); 
 
            textAnnotation1 = new TextAnnotation(); 
            textAnnotation1.CoordinateUnit = CoordinateUnit.Pixel; 
            textAnnotation1.YAxisName = "row1YAxis"; 
            textAnnotation1.Text = "TextAnnotation 1"; 
            chart.Annotations.Add(textAnnotation1); 
 
            textAnnotation2 = new TextAnnotation(); 
            textAnnotation2.CoordinateUnit = CoordinateUnit.Pixel; 
            textAnnotation2.YAxisName = "row1YAxis"; 
            textAnnotation2.Text = "TextAnnotation 2"; 
            chart.Annotations.Add(textAnnotation2); 
 
        } 
 
        private void UpdateAnnotation() 
        { 
            var xPos = chart.ValueToPoint(xAxis, xAxis.VisibleRange.Start)+chart.SeriesClipRect.Left + 10; 
 
            var yPos = chart.ValueToPoint(row1YAxis, row1YAxis.VisibleRange.End) + 5; 
 
            textAnnotation1.X1 = xPos; 
            textAnnotation1.Y1 = yPos; 
 
            textAnnotation2.X1 = xPos; 
            textAnnotation2.Y1 = yPos + 20; 
        } 
 
        private void chart_ZoomChanged(object sender, ZoomChangedEventArgs e) 
        { 
            UpdateAnnotation(); 
        } 
 
        private void row1YAxis_ActualRangeChanged(object sender, ActualRangeChangedEventArgs e) 
        { 
            UpdateAnnotation(); 
        } 
 
        private void chart_SizeChanged(object sender, SizeChangedEventArgs e) 
        { 
            UpdateAnnotation(); 
        } 
 
        private void NumericalAxis_ActualRangeChanged(object sender, ActualRangeChangedEventArgs e) 
        { 
            UpdateAnnotation(); 
        } 
 
Here we have set the left position with 10 pixels, top position with 5 pixels and two annotation gap with 20 pixels. You can modify these values as per your requirement. Please find the sample from the following location.  
 
 
Please let us know if you have any queries.  
 
Thanks, 
Muneesh Kumar G 



TO Tom October 23, 2018 02:14 PM UTC

Thank you Muneesh, this helped me solve the problem. However, I changed chart.ValueToPoint to row1Yaxis.ArrangeRect.Y as it was more suitable for my application.


MK Muneesh Kumar G Syncfusion Team October 24, 2018 06:00 AM UTC

Hi Tom, 
 
Thanks for your update. Please let us know if you have any other queries. 
 
Thanks, 
Muneesh Kumar G 


Loader.
Up arrow icon