### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: BottomAxis Height  (Read 580 times)

#### kapibara

• Hero Member
• Posts: 610
##### BottomAxis Height
« on: December 10, 2023, 08:46:39 am »
Is it possible to get the height of a BottomAxis?

The idea is to show BottomAxis only for the bottom pane and not for panes above it. The
Axis height would be used to adjust the height of the panes so the chart in the bottom-most pane doesn't appear smaller than the others because the axis takes up some of the graphs space.

Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

#### kapibara

• Hero Member
• Posts: 610
##### Re: BottomAxis Height
« Reply #1 on: December 12, 2023, 12:15:00 am »
Finding the size of the chart area (where series are plotted, excluding axises and margins) would also work.

TChartAxis and TChartAxisList has a public method named Measure, could that be used to find heights of parts of the chart?
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

#### wp

• Hero Member
• Posts: 11769
##### Re: BottomAxis Height
« Reply #2 on: December 12, 2023, 12:57:38 am »
You could use the Chart's ClipRect to determine the "plot area" (rectangle enclosed by the axes); however, it can change its value depending on context. I think it is a bit safer to query the chart's CurrentExtent and to convert the two corner points to image coordinates:
Code: Pascal  [Select][+][-]
1. function CalcPlotArea(AChart: TChart): TRect;
2. var
3.   ext: TDoubleRect;  // requries unit TAChartUtils;
4.   P1, P2: TPoint;
5. begin
6.   ext := AChart.CurrentExtent;
7.   P1 := AChart.GraphToImage(ext.a);  // left/bottom corner
8.   P2 := AChart.GraphToImage(ext.b);  // right/top corner
9.   Result := Rect(P1.X, P2.Y, P2.X, P1.Y);
10. end;
But note that this calculation is only successful after the chart has been painted.

#### kapibara

• Hero Member
• Posts: 610
##### Re: BottomAxis Height
« Reply #3 on: December 12, 2023, 06:37:21 am »
Seems to work, thanks! Like you warned, I had to add Application.ProcessMessages before calling CalcPlotArea to avoid EChartError, "scaling not yet initialized".
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit