Page 1 of 1

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

Posted: Wed Jul 20, 2016 12:45 pm
by 16575142
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.

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

Posted: Wed Jul 20, 2016 1:27 pm
by yeray
Hello,

Take a look a the PlaceAxes method I implemented for a customer some time ago here.

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

Posted: Wed Jul 20, 2016 9:53 pm
by 16575142
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.

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

Posted: Thu Jul 21, 2016 7:20 am
by yeray
Hello,

Feel free to share your method(s) if you think it solves the situation better! :)