Page 1 of 1

aligning the chart title

Posted: Mon Jan 23, 2012 5:02 am
by 5886857
I'd like to have the chart title left-aligned to the y-axis. Selecting Alignment=left aligns the title with the margin of the chart, so it starts over the y-axis title, rather than over the y axis itself.
title_align.png
title_align.png (20.44 KiB) Viewed 2498 times
Custom positioning isn't quite what my customer is looking for, since using an absolute value is probably slightly off in some instances. And in any case, turning on custom positioning of the title expands the border of the graph such that the chart title appears on the graph itself, rather than above it (which is not desired).

Re: aligning the chart title

Posted: Mon Jan 23, 2012 3:17 pm
by yeray
Hi Trusler,

What about a TAnnotation tool? The following seems to give a quite good result for me here:

Code: Select all

  with Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool do
  begin
    Chart1.Title.Visible:=false;
    Chart1.MarginTop:=25;

    Text:='TChart';
    Shape.Font.Color:=clBlue;
    Shape.Transparent:=true;
    Shape.Font.Size:=8;
    Shape.Font.Name:='Verdana';
    Left:=Chart1.Axes.Left.PosAxis;
    Top:=Chart1.Axes.Left.IStartPos - 20;
  end;
And you could call the following at your OnScroll, OnZoom and OnUndoZoom to force the text to be positioned on place even when the labels make the margin on the axis to be changed.

Code: Select all

  Chart1.Draw;
  if (Chart1.Tools.Count>0) then
    (Chart1.Tools[0] as TAnnotationTool).Left:=Chart1.Axes.Left.PosAxis;