Size of chart elements

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Toreba
Newbie
Newbie
Posts: 1
Joined: Mon Oct 04, 2021 12:00 am

Size of chart elements

Post by Toreba » Tue Oct 05, 2021 9:29 am

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?

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

Re: Size of chart elements

Post by Yeray » Tue Oct 05, 2021 1:28 pm

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 4043 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;
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