Add Annotations to ViewPolar
Moderator: Queue Moderators
Add Annotations to ViewPolar
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
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
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Add Annotations to ViewPolar
It really should work just fine. I added annotation in the demo application's first polar example "Line series, sector".
This is the CreateChart method of the example.
Maybe your software rendering flow is broken. Forgot to include a matching EndUpdate to BeginUpdate call?
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
Re: Add Annotations to ViewPolar
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.
Thank you.
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.
Thank you.
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Add Annotations to ViewPolar
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: Are you looking for this?
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.
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.
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: Are you looking for this?
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.
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.
LightningChart Support Team, PT
Re: Add Annotations to ViewPolar
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.
There is still 1 property I could not find, it is the size of the annotation, it is a little but too large.
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Add Annotations to ViewPolar
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
Re: Add Annotations to ViewPolar
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.
In the properties of the Annotation:
Sizing: ScreenCoordinates
Size Screen Coors: Height/Width ...they are the size of the rectangle.
Re: Add Annotations to ViewPolar
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?
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?
Re: Add Annotations to ViewPolar
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?
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?
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Add Annotations to ViewPolar
2. Set chart.ViewPolar.Axis[0].SupplyCustomAngleString event handler.
in the 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 = "";
}
LightningChart Support Team, PT
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Add Annotations to ViewPolar
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;
LightningChart Support Team, PT
Re: Add Annotations to ViewPolar
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;"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 = ""; }
- ArctionPasi
- Posts: 1367
- Joined: Tue Mar 26, 2013 10:57 pm
- Location: Finland
- Contact:
Re: Add Annotations to ViewPolar
It also needs setting
chart.ViewPolar.Axes[0].AutoFormatLabels = false;
Sorry I forgot to add that.
chart.ViewPolar.Axes[0].AutoFormatLabels = false;
Sorry I forgot to add that.
LightningChart Support Team, PT