Measure axis size (inlc. title, labels, etc..)

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
PoLabs
Newbie
Newbie
Posts: 13
Joined: Tue Aug 04, 2015 12:00 am

Measure axis size (inlc. title, labels, etc..)

Post by PoLabs » Wed Jul 20, 2016 12:45 pm

Hi,

I am creating vertical axes in runtime and I would like to know how can I measure how much place one axis will take (including labels, title etc..)?

Now I use constant 70px (experimentaly defined) for each axis... and then setup Chart.MarginLeft = N * 70 where N is number of axes I create. However this is quite clumsy solution and I would like to make it more flexible because font size of title and axis labels can change and that affects overall axis width thus chart.MarginLeft.

My idea is to calculate Chart.MarginLeft according to all axes aligned each to other.

I attached two images. Width.png shows alignment for single axis and constant 70px of Chart.MarginLeft. Second picture aligned_axes.png shows two axes aligned left and they are aligned at same 70px spacing (relative to each other) which is not OK as you can see orange axis is overlapping title of purple one. So I would like o calculate the size to set up chart.LeftMargin properly so that axes will be positioned properly according to font size etc..

Just for the idea my code was:

Code: Select all

Result := Chart.CustomAxes[AxIdx].MaxLabelsWidth +
                    Chart.CustomAxes[AxIdx].TickLength +
                    Chart.CustomAxes[AxIdx].Shape.Height  + 7; // height - because orientation is 90 deg... so height is basically width of 90 deg rotate title
But I always get less than 70px so I guess I am missing something here. Can you help me with that, please.
Attachments
aligned_axes.png
aligned_axes.png (4.38 KiB) Viewed 9492 times
width.png
Fixed width
width.png (3.41 KiB) Viewed 9483 times

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

Re: Measure axis size (inlc. title, labels, etc..)

Post by Yeray » Wed Jul 20, 2016 1:27 pm

Hello,

Take a look a the PlaceAxes method I implemented for a customer some time ago here.
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

PoLabs
Newbie
Newbie
Posts: 13
Joined: Tue Aug 04, 2015 12:00 am

Re: Measure axis size (inlc. title, labels, etc..)

Post by PoLabs » Wed Jul 20, 2016 9:53 pm

Hi,

thanks for the link. Very helpful.

I have very similar solution. Actually the only difference is that mine is not recursive but iterative. I use Title for each axis and I have custom labels so this affects everything... However I managed to find good solution which works fine.

I manually calculate maximum label size by generating labels and using Chart.Canvas.TextWidth and similar for Title. This also works fine with different font size for title or /and labels.

Thanks for the idea anyway.

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

Re: Measure axis size (inlc. title, labels, etc..)

Post by Yeray » Thu Jul 21, 2016 7:20 am

Hello,

Feel free to share your method(s) if you think it solves the situation better! :)
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