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
TeeChart 2010 and Title alignment
Re: TeeChart 2010 and Title alignment
Hi johnnix,
If I understood correctly, you could set your title position relative to an axis position doing something as follows:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: TeeChart 2010 and Title alignment
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):
Kindest regards
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;
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Re: TeeChart 2010 and Title alignment
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:
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.
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;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |