I need to calculate the x midpoint of a chart in order to plot a string.
I am using:
Midpoint = ((Points1.Chart.Axes.Bottom.Maximum - Points1.Chart.Axes.Bottom.Minimum) / 2) + Points1.Chart.Axes.Bottom.Minimum
This works fine for a manual scale but if I set the chart scale to automatic, the calculation is out by a few percent:
Points1.Chart.Axes.Bottom.AutomaticMaximum = True
Points1.Chart.Axes.Right.AutomaticMaximum = True
Points1.Chart.Axes.Left.AutomaticMaximum = True
Points1.Chart.Axes.Top.AutomaticMaximum = True
Points1.Chart.Axes.Right.AutomaticMinimum = True
Points1.Chart.Axes.Bottom.AutomaticMinimum = True
Points1.Chart.Axes.Left.AutomaticMinimum = True
Points1.Chart.Axes.Top.AutomaticMinimum = True
The Points1.Chart.Axes.Bottom.Maximum and Points1.Chart.Axes.Bottom.Minimum do not match the plotted min and max shown on the x axis.
Is there a better way to calculate the midpoint for automatic scale?
Calc Midpoint of chart
Re: Calc Midpoint of chart
Hello lilo,
I think the internal offset could be causing this confusion. However, I think the internal minimum and maximum are in general equal in an axis so I'm not sure to see how this could affect the calculated midpoint. What series are you using?
Another possibility would be using the axes IStartPos and IEndPos:
I think the internal offset could be causing this confusion. However, I think the internal minimum and maximum are in general equal in an axis so I'm not sure to see how this could affect the calculated midpoint. What series are you using?
Another possibility would be using the axes IStartPos and IEndPos:
Code: Select all
double minX = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IStartPos);
double maxX = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IEndPos);
double minY = tChart1.Axes.Left.CalcPosPoint(tChart1.Axes.Left.IEndPos);
double maxY = tChart1.Axes.Left.CalcPosPoint(tChart1.Axes.Left.IStartPos);
double midX = ((maxX - minX) / 2) + minX;
double midY = ((maxY - minY) / 2) + minY;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Calc Midpoint of chart
This works, thank you
Re: Calc Midpoint of chart
Hi lilo,
I'm happy to hear that. You're welcome!
I'm happy to hear that. You're welcome!
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |