TeeChart 2010 and Title alignment

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
johnnix
Advanced
Posts: 192
Joined: Tue Jul 10, 2007 12:00 am

TeeChart 2010 and Title alignment

Post by johnnix » Thu Sep 30, 2010 5:35 am

Hello,

Long time ago I posted a question regarding on how I can align the chart Title caption relative to left and right axis area. Apparently I have the same issue with 2010 version.... Is it possible to do so as it looks really ugly :(

Regards

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

Re: TeeChart 2010 and Title alignment

Post by Yeray » Thu Sep 30, 2010 1:38 pm

Hi johnnix,

If I understood correctly, you could set your title position relative to an axis position doing something as follows:

Code: Select all

uses series;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  Chart1.Title.Left:=Chart1.Axes.Left.PosAxis;
  Chart1.Title.Top:=10;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Align:=alClient;
  Chart1.View3D:=false;

  Chart1.MarginTop:=8;
  Chart1.Title.CustomPosition:=true;
  Chart1.Title.Text.Text:='My custom title aligned';
  Chart1.Title.Font.Size:=10;
  Chart1.Title.Font.Color:=clRed;

  with Chart1.AddSeries(TPointSeries) do FillSampleValues();

  Chart1.Draw;
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

johnnix
Advanced
Posts: 192
Joined: Tue Jul 10, 2007 12:00 am

Re: TeeChart 2010 and Title alignment

Post by johnnix » Fri Oct 01, 2010 5:16 am

Hello,

Thank you for your reply. The code you sent me does not work exactly as I wanted. Below is a sample where you may see that there is a difference (the blue title is the right one):

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var l, r, w, x,y: integer;
begin
  l := Chart1.Axes.Bottom.IStartPos;
  r := Chart1.Axes.Bottom.IEndPos;
  chart1.Canvas.Font.Assign(chart1.Title.Font);
  chart1.Canvas.Font.Color := clBlue;
  w := Chart1.Canvas.TextWidth(chart1.Title.Caption);
  chart1.Title.Left := round(l + (r-l)*0.50 - w*0.50);
  chart1.Canvas.TextOut(round(l + (r-l)*0.50 - w*0.50),8,chart1.Title.Caption);
  Chart1.Title.Top:=10;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Chart1.Align:=alClient;
  Chart1.View3D:=false;

  Chart1.MarginTop:=8;
  Chart1.Title.CustomPosition:=true;
  Chart1.Title.Text.Text:='My custom title aligned';
  Chart1.Title.Font.Size:=10;
  Chart1.Title.Font.Color:=clRed;

  with Chart1.AddSeries(TPointSeries) do FillSampleValues();
  chart1.Series[0].ShowInLegend := false;

  Chart1.Draw;
end;
Kindest regards

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: TeeChart 2010 and Title alignment

Post by Narcís » Fri Oct 01, 2010 2:59 pm

Hi johnnix,

This is because you have to take into account the horizontal separation between the title text and its bounding shape, you'll see what I mean in this code snippet:

Code: Select all

uses Series;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var l, r, w, x, y, pos: integer;
begin
  l := Chart1.Axes.Bottom.IStartPos;
  r := Chart1.Axes.Bottom.IEndPos;
  w := Chart1.Canvas.TextWidth(Chart1.Title.Caption);
  pos:=round(l + (r-l)*0.50 - w*0.50);

  Chart1.Title.CustomPosition:=true;
  Chart1.Title.Left:=pos;
  Chart1.Title.Top:=10;

  Chart1.Canvas.Font.Assign(Chart1.Title.Font);
  Chart1.Canvas.Font.Color:=clBlue;
  Chart1.Canvas.TextOut(pos,8,Chart1.Title.Caption);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Align:=alClient;
  Chart1.View3D:=false;
  Chart1.MarginTop:=8;

  Chart1.Title.Text.Text:='My custom title aligned';
  Chart1.Title.Font.Size:=10;
  Chart1.Title.Font.Color:=clRed;
  Chart1.Title.Transparent:=False;

  Chart1.AddSeries(TPointSeries.Create(Self)).FillSampleValues();
  Chart1[0].ShowInLegend:=false;

  Chart1.Draw;
end;
In the code above you can see how custom drawn text aligns perfectly with title's frame. I'm afraid there's no property to control text's margin.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply