Add Annotations to ViewPolar

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
pct
Posts: 24
Joined: Mon Oct 21, 2013 1:44 pm

Add Annotations to ViewPolar

Post by pct » Mon Oct 21, 2013 7:37 pm

Hi,
I'm trying to add annotation in ViewPolar. I cannot add anything.

--------------------------------------------------------------
AnnotationPolar annotation = new AnnotationPolar(m_chart.ViewPolar, m_chart.ViewPolar.Axes[0]); OR AnnotationPolar();
annotation.Style = AnnotationStyle.Rectangle;
annotation.TextStyle.Visible = true;
annotation.LocationCoordinateSystem = CoordinateSystem.ScreenCoordinates; OR CoordinateSystem.AxisValues;
annotation.Text = "Nsssssss";
m_chart.ViewPolar.Annotations.Add(annotation);
--------------------------------------------------------------

Thanks.
Pct

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

Re: Add Annotations to ViewPolar

Post by ArctionPasi » Tue Oct 22, 2013 2:58 pm

It really should work just fine. I added annotation in the demo application's first polar example "Line series, sector".
Polar chart
Polar chart
polar.jpg (144.4 KiB) Viewed 26485 times
This is the CreateChart method of the example.

Code: Select all

/// <summary>
		/// Create chart
		/// </summary>
		private void CreateChart()
		{
			// Clear any gridChart's children.
			gridChart.Children.Clear();

			if (m_chart != null)
			{
				// If a chart is already created, dispose it.
				m_chart.Dispose();
				m_chart = null;
			}

			// Create a new chart.
			m_chart = new LightningChartUltimate.LightningChartUltimate(LicenseKeys.LicenseKeyStrings.LightningChartUltimate);
			m_chart.ChartName = "Polar line series chart";

			//Disable rendering, strongly recommended before updating chart properties
			m_chart.BeginUpdate();

			//Set active view
			m_chart.ActiveView = ActiveView.ViewPolar;

			//Get 1st polar axis and set it up
			AxisPolar axis = m_chart.ViewPolar.Axes[0];
			axis.MajorGrid.Visible = true;
			axis.MinorGrid.Visible = true;
			axis.TickMarkLocation = PolarGridTickmarkLocation.Outside;
			axis.Reversed = false;
			axis.InnerCircleRadiusPercentage = 10;
			axis.MajorDivCount = 4;
			axis.MinAmplitude = 0;
			axis.MaxAmplitude = 20;
			axis.MouseScaling = true;
			axis.MouseScrolling = true;
			axis.Units.RadialOffsetPercentage = 100;
			axis.Visible = true;

			//Remove existing PointLineSeries
			m_chart.ViewPolar.PointLineSeries.Clear();

			//Create new PointLineSeries
			PointLineSeriesPolar plsp = new PointLineSeriesPolar(m_chart.ViewPolar, axis);
			plsp.PointsVisible = true;
			plsp.PointStyle.Width = 4;
			plsp.PointStyle.Height = 4;


			//Create data for series
			int iCount = 360;
			PolarSeriesPoint[] aPoints = new PolarSeriesPoint[iCount];

			Random rnd = new Random();
			for (int i = 0; i < iCount; i++)
			{
				aPoints[i].Amplitude = 10.0 + 3.0 * rnd.NextDouble() + 5.0 * Math.Cos(Math.PI * (double)i / 180.0);
				aPoints[i].Angle = (double)i;
			}
			plsp.Points = aPoints;

			//Add series to chart
			m_chart.ViewPolar.PointLineSeries.Add(plsp);

			//Create sector
			Sector sector = new Sector(m_chart.ViewPolar, axis);
			sector.Behind = true;
			sector.MinAmplitude = 10;
			sector.MaxAmplitude = 20;
			sector.BeginAngle = 0;
			sector.EndAngle = 45;
			sector.BorderlineStyle.Color = Colors.Cyan;
			sector.BorderlineStyle.Width = 2;
			m_chart.ViewPolar.Sectors.Add(sector);


            Arction.WPF.LightningChartUltimate.Annotations.AnnotationPolar annotation 
                = new Arction.WPF.LightningChartUltimate.Annotations.AnnotationPolar(m_chart.ViewPolar, m_chart.ViewPolar.Axes[0]);
            annotation.Style = AnnotationStyle.Rectangle;
            annotation.TextStyle.Visible = true;
            annotation.LocationCoordinateSystem = CoordinateSystem.ScreenCoordinates; 
            annotation.Text = "Nsssssss";
            m_chart.ViewPolar.Annotations.Add(annotation);

			//Allow chart rendering
			m_chart.EndUpdate();

			gridChart.Children.Add(m_chart);
		}

Maybe your software rendering flow is broken. Forgot to include a matching EndUpdate to BeginUpdate call?
LightningChart Support Team, PT

pct
Posts: 24
Joined: Mon Oct 21, 2013 1:44 pm

Re: Add Annotations to ViewPolar

Post by pct » Thu Oct 24, 2013 8:23 pm

Thanks, I moved my code to a different function and it worked.

I have two more questions.
Q1:
Is there a way to control the position of the Annotation? By the 0 degree, I would like to have an annotion "North", 90 degree "South", etc.

Q2:
Also, I want to have the 0 value on the top and going from 0 to 360 clockwise. I wise the demo to rotate the compass the way I wanted, but the values are inverted.

Image

Thank you.

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

Re: Add Annotations to ViewPolar

Post by ArctionPasi » Thu Oct 24, 2013 9:57 pm

Q1 & Q2,

I think you need to rotate the axis coordinate system, not the whole chart.

In ExamplePolarVectors,
ViewPolar.Axes[0].Reversed = true;
ViewPolar.Axes[0].AngleOrigin = 270;

Then it looks like this:
Polar vectors with rotated coordinates
Polar vectors with rotated coordinates
polarVectors.jpg (143.22 KiB) Viewed 26478 times
Are you looking for this? 8-)

Even this is a WPF chart related thread, it's a good practice to run the examples with WinForms demo application too. It has a great advantage over WPF demo app - it has a property grid you can use to change properties and investigate their effect.
WinForms demo app with property grid
WinForms demo app with property grid
winforms_demo_app_property_grid.jpg (219.43 KiB) Viewed 26478 times
The property tree is almost identical to WPF chart's property tree, and practically all examples exist in both demo applications. Speeds up learning of the object model, I think. :geek:
LightningChart Support Team, PT

pct
Posts: 24
Joined: Mon Oct 21, 2013 1:44 pm

Re: Add Annotations to ViewPolar

Post by pct » Fri Oct 25, 2013 8:52 pm

Thanks, it is very helpful to try it in Winform, much easier to see all the properties and test it.

There is still 1 property I could not find, it is the size of the annotation, it is a little but too large.

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

Re: Add Annotations to ViewPolar

Post by ArctionPasi » Fri Oct 25, 2013 9:38 pm

The arrow length is controlled by annotation.LocationAxisValues (line start point) and TargetAxisValues (head of arrow position). The thickness of the line can be set by ArrowLineStyle.Width. :)
LightningChart Support Team, PT

pct
Posts: 24
Joined: Mon Oct 21, 2013 1:44 pm

Re: Add Annotations to ViewPolar

Post by pct » Tue Oct 29, 2013 7:50 pm

No, I was talking about the size of the rectangle, not the arrow, but I found how. :)

In the properties of the Annotation:
Sizing: ScreenCoordinates
Size Screen Coors: Height/Width ...they are the size of the rectangle.

pct
Posts: 24
Joined: Mon Oct 21, 2013 1:44 pm

Re: Add Annotations to ViewPolar

Post by pct » Tue Oct 29, 2013 8:21 pm

Two other questions:

1 . Is there a way to know the width and height of the ViewPolar chart, I can only find the dimension of the only window.

2. Is it possible to change 0 by N, 180 by S, 90 by E, 270 by W?

pct
Posts: 24
Joined: Mon Oct 21, 2013 1:44 pm

Re: Add Annotations to ViewPolar

Post by pct » Wed Oct 30, 2013 9:38 pm

So, is it possible?

1 . Is there a way to know the width and height of the ViewPolar chart, I can only find the dimension of the only window.

2. Is it possible to change 0 by N, 180 by S, 90 by E, 270 by W?

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

Re: Add Annotations to ViewPolar

Post by ArctionPasi » Fri Nov 01, 2013 11:51 am

2. Set chart.ViewPolar.Axis[0].SupplyCustomAngleString event handler.

in the handler:

Code: Select all

private void AngleAsString(object sender, AxisPolarBase.AxisAngleEventArguments args)
{
int degrees = (int)Math.Round(180f * args.Angle / Math.PI);
if(degrees == 0)
args.AngleAsString = "N"; 

else if(degrees == 180)
args.AngleAsString = "S"; 

else if(degrees == 90)
args.AngleAsString = "E"; 

else if(degrees == 270)
args.AngleAsString = "W"; 

else args.AngleAsString = ""; 
}
:mrgreen:
LightningChart Support Team, PT

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

Re: Add Annotations to ViewPolar

Post by ArctionPasi » Fri Nov 01, 2013 12:14 pm

1. Calculate the center point and size (diameter) as follows:

Code: Select all

double maxW = m_chart.ActualWidth - m_chart.ViewPolar.Margins.Left - m_chart.ViewPolar.Margins.Top;
            double maxH = m_chart.ActualHeight - m_chart.ViewPolar.Margins.Top - m_chart.ViewPolar.Margins.Bottom;
            Point centerPoint = new Point(m_chart.ViewPolar.Margins.Left + maxW / 2.0, m_chart.ViewPolar.Margins.Top + maxH / 2.0);
            double diameter = maxH; 
            if( maxW < maxH)
                diameter = maxW;
:mrgreen:
LightningChart Support Team, PT

pct
Posts: 24
Joined: Mon Oct 21, 2013 1:44 pm

Re: Add Annotations to ViewPolar

Post by pct » Fri Nov 01, 2013 7:21 pm

ArctionPasi wrote:2. Set chart.ViewPolar.Axis[0].SupplyCustomAngleString event handler.

in the handler:

Code: Select all

private void AngleAsString(object sender, AxisPolarBase.AxisAngleEventArguments args)
{
int degrees = (int)Math.Round(180f * args.Angle / Math.PI);
if(degrees == 0)
args.AngleAsString = "N"; 

else if(degrees == 180)
args.AngleAsString = "S"; 

else if(degrees == 90)
args.AngleAsString = "E"; 

else if(degrees == 270)
args.AngleAsString = "W"; 

else args.AngleAsString = ""; 
}
:mrgreen:
At what moment the event SupplyCustomAngleString will be raised? I'm doing it right after the creation of the chart instance and my handler is never called "m_chart.ViewPolar.Axes[0].SupplyCustomAngleString += AngleAsString;"

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

Re: Add Annotations to ViewPolar

Post by ArctionPasi » Fri Nov 01, 2013 8:40 pm

It also needs setting
chart.ViewPolar.Axes[0].AutoFormatLabels = false;

Sorry I forgot to add that. :roll:
LightningChart Support Team, PT

Post Reply