Page 1 of 1
TeeChart 2010 and Title alignment
Posted: Thu Sep 30, 2010 5:35 am
by 10046032
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
Re: TeeChart 2010 and Title alignment
Posted: Thu Sep 30, 2010 1:38 pm
by yeray
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;
Re: TeeChart 2010 and Title alignment
Posted: Fri Oct 01, 2010 5:16 am
by 10046032
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
Re: TeeChart 2010 and Title alignment
Posted: Fri Oct 01, 2010 2:59 pm
by narcis
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.