Author Topic: Finding and settin plot width  (Read 352 times)


  • Sr. Member
  • ****
  • Posts: 279
Finding and settin plot width
« on: January 05, 2021, 09:45:27 am »
I have a simple TChart, with a TShape underneath. I want to align the left and right of the TShape with the left/right of the TChart plot area (that is excluding the vertical scale labels). Is there a simple way of finding/setting the width of the TChart plot area?


  • Hero Member
  • *****
  • Posts: 8378
Re: Finding and settin plot width
« Reply #1 on: January 05, 2021, 11:09:29 am »
There is a Chart.ClipRect, but this may change while the chart is drawn. The safest way, in my opinion, is to use the chart's CurrentExtent and convert it to screen coordinates. The CurrentExtent is a TDoubleRect defined by the left/bottom and right/top intersection of the axis lines. Units are the internal "graph" units which are mostly equal to the units plotted on the axes. Conversion can be done by the chart's GraphToImage functions.

Code: Pascal  [Select][+][-]
  1. uses
  2.   TAChartUtils;  // for TDoubleRect;
  4. function GetChartAxisRect(AChart: TChart): TRect;
  5. var
  6.   ext: TDoubleRect;
  7. begin
  8.   ext := AChart.CurrentExtent;
  9.   Result.Left := AChart.XGraphToImage(ext.a.x);
  10.   Result.Right := AChart.XGraphToImage(ext.b.x);
  11.   Result.Top := AChart.YGraphToImage(ext.b.y);
  12.   Result.Bottom := AChart.YGraphToImage(ext.a.y);
  13. end;
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...


TinyPortal © 2005-2018