Set AnnotationXY to be Displayed on Top Right of Chart

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Set AnnotationXY to be Displayed on Top Right of Chart

Post by hallo888 » Thu Sep 18, 2014 2:34 am

Hi,

I would like to have the annotation to always show up at the top right hand corner of the chart, no matter what size. Below is what i did.

Set the annotationXY coordinate system to "ScreenCoordinates" to reference in pixels. First to compute the size of the annotation box, get the width and height of the chart in pixels.

Code: Select all


PointInt p = chart.MeasureText(annotation.Text,annotation.TextStyle.Font);
int widthPixel = p.X + annotation.AutoSizePadding*2;
int heightPixel = p.Y + annotation.AutoSizePadding*2;

annotation.LocationAxisValues.X = chart.ActualWidth - widthPixel;
annotation.LocationAxisValues.Y = chart.ActualHeight - heightPixel;
But the above resulting in the annotation text showing up in the top left hand corner of the chart with part of the annotation text being clipped.

What do i need to change to achieve what i need.

And also, is it also possible to print the Annotation text outside the chart, along the margins of the chart so as not to block the chart contents? What do i need to set to do that?

Thanks!

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Set AnnotationXY to be Displayed on Top Right of Chart

Post by ArctionPasi » Mon Sep 22, 2014 1:07 pm

Code: Select all


m_chart.SizeChanged += m_chart_SizeChanged;

AnnotationXY annot = new AnnotationXY(m_chart.ViewXY, m_chart.ViewXY.XAxes[0], m_chart.ViewXY.YAxes[0]);
            annot.Anchor.SetValues(1, 0); //Location sets now the top-right of the annotation. 
            annot.Style = AnnotationStyle.Rectangle;
            annot.ClipInsideGraph = false; 
            annot.LocationCoordinateSystem = CoordinateSystem.ScreenCoordinates;
            m_chart.ViewXY.Annotations.Add(annot);


void m_chart_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            m_chart.BeginUpdate(); 

            m_chart.ViewXY.Annotations[0].LocationScreenCoords.X = m_chart.ViewXY.GetMarginsRect().Right;
            m_chart.ViewXY.Annotations[0].LocationScreenCoords.Y = m_chart.ViewXY.GetMarginsRect().Top; 

            m_chart.EndUpdate(); 

        }


Then it aligns it top top-right:
Chart annotation aligned to top-right
Chart annotation aligned to top-right
Annotation aligned to graph top-right.jpg (102.84 KiB) Viewed 7736 times
By setting
annot.ClipInsideGraph = false;

It will allow the annotation to render over the margins:
Annotation over margins
Annotation over margins
Annotation over margins.jpg (46.21 KiB) Viewed 7736 times
LightningChart Support Team, PT

Post Reply