Page 1 of 1

Size of chart elements

Posted: Tue Oct 05, 2021 9:29 am
by 16591932
Hi,

I'm trying to understand the vertical alignments of the various elements that make up the chart. At run time it is possible to get the size in pixels the height of the top and bottom margins, the chart title, the axes titles, the chart rectangle itself, and the legend. But I can't see how to get the height occupied by the axis labelling. Is there a property that returns this?

Re: Size of chart elements

Posted: Tue Oct 05, 2021 1:28 pm
by yeray
Hello,

I did an example trying to show all the heights involved in a simple chart:
Project1_2021-10-05_15-23-07.png
Project1_2021-10-05_15-23-07.png (19.6 KiB) Viewed 3249 times

Code: Select all

uses Series;

type TCustomTeePanelAccess=class(TCustomTeePanel);

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Hide;
  Chart1.Gradient.Visible:=False;
  Chart1.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;

  Chart1.AddSeries(TBarSeries).FillSampleValues;

  RecalcHeights;
end;

procedure TForm1.RecalcHeights;
var total: Integer;

  procedure AddValue(const title: String; const AValue: Integer);
  begin
    Inc(total, AValue);
    Memo1.Lines.Add(title + ': ' + IntToStr(AValue) + ', Subtotal: ' + IntToStr(total));
  end;

begin
  Chart1.Draw;

  Memo1.Clear;
  Memo1.Lines.Add('*** Heights ***');
  Memo1.Lines.Add('Total Chart: ' + IntToStr(Chart1.Height));
  Memo1.Lines.Add('');

  total:=0;
  AddValue('BorderSize', TCustomTeePanelAccess(Chart1).BorderSize);
  if (Chart1.MarginUnits = muPixels) then
     AddValue('Margin Top', Chart1.MarginTop)
  else
     AddValue('Margin Top', Chart1.Height*Chart1.MarginTop div 100);

  AddValue('Title', Chart1.Title.Height);
  AddValue('Title Margin', Chart1.Title.VertMargin);
  AddValue('ChartRect', Chart1.ChartRect.Height);
  with Chart1.Axes.Bottom do
  begin
    AddValue('Bottom Axis Ticks Margin', Axis.Width+1);
    AddValue('Bottom Axis Ticks', TickLength);
    AddValue('Bottom Axis Labels', Abs(LabelsFormat.Height));
  end;
  if (Chart1.MarginUnits = muPixels) then
    AddValue('Margin Bottom', Chart1.MarginBottom)
  else
    AddValue('Margin Bottom', Chart1.Height*Chart1.MarginBottom div 100);

  AddValue('BorderSize', TCustomTeePanelAccess(Chart1).BorderSize);
end;