Calc Midpoint of chart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
lilo
Newbie
Newbie
Posts: 29
Joined: Thu Sep 30, 2010 12:00 am

Calc Midpoint of chart

Post by lilo » Tue Aug 30, 2011 9:26 am

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?

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Calc Midpoint of chart

Post by Yeray » Tue Aug 30, 2011 10:19 am

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:

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,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

lilo
Newbie
Newbie
Posts: 29
Joined: Thu Sep 30, 2010 12:00 am

Re: Calc Midpoint of chart

Post by lilo » Tue Aug 30, 2011 10:48 am

This works, thank you

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Calc Midpoint of chart

Post by Yeray » Tue Aug 30, 2011 1:31 pm

Hi lilo,

I'm happy to hear that. You're welcome! :)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply