Page 1 of 1

x-axis title offset

Posted: Mon May 04, 2015 9:45 am
by 16573450
Hi,
apologise if this question was already addressed, but how can I set an offset to an axis title? How can I do that?
thanks in advance

Re: x-axis title offset

Posted: Mon May 04, 2015 2:38 pm
by yeray
Hello,

I'm afraid the automatic alignment doesn't allow offsets. Instead, you could use a custom position:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Title.CustomPosition:=true;
  Chart1.Title.Left:=100;
  Chart1.Title.Top:=50;
end;

Re: x-axis title offset

Posted: Mon May 04, 2015 4:36 pm
by 16573450
Hi,
thanks for the prompt reply, but my question was about the position of the axis label, not the chart title.
I need to have:
chart1.BottomAxis.Title.Caption := 'bla';
I want to change the position of this label. How can I do this?
thanks, nabil

Re: x-axis title offset

Posted: Tue May 05, 2015 9:20 am
by yeray
Hi Nabil,
cssesuc wrote:thanks for the prompt reply, but my question was about the position of the axis label, not the chart title.
Oups, I misread that.
cssesuc wrote:I need to have:
chart1.BottomAxis.Title.Caption := 'bla';
I want to change the position of this label. How can I do this?
I'm afraid that's not possible. Instead, you should use an annotation tool and set its position manually.

Re: x-axis title offset

Posted: Wed May 06, 2015 9:20 am
by 16573450
thanks for the reply. Sorry, I am not familiar with the TeeChart library yet.
You write: "you should use an annotation tool and set its position manually."
could you provide me with some lines of code on how to implement that for the bottom axis?
thanks for your valuable help

Re: x-axis title offset

Posted: Wed May 06, 2015 10:01 am
by yeray
Hello,

Here you are:

Code: Select all

uses Series, TeeTools;

var annot1: TAnnotationTool;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TBarSeries).FillSampleValues;

  annot1:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;

  with annot1 do
  begin
    Text:='This is a bottom axis title with offset';
    Shape.Transparent:=true;
  end;
end;

procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
var xOffset, tmpWidth, tmpHeight: Integer;
begin
  xOffset:=10;

  annot1.Shape.CustomPosition:=true;

  tmpWidth:=annot1.Width;
  tmpHeight:=annot1.Height;

  Chart1.Canvas.AssignFont(annot1.Shape.Font);
  if tmpWidth=0 then
    tmpWidth:=Chart1.Canvas.TextWidth(annot1.Text);

  if tmpHeight=0 then
    tmpHeight:=Chart1.Canvas.TextHeight(annot1.Text);

  annot1.Left:=Chart1.Axes.Bottom.IStartPos + Chart1.Axes.Bottom.IAxisSize div 2 - tmpWidth div 2 + xOffset;
  annot1.Top:=Chart1.Height - tmpHeight - 10;
end;

Re: x-axis title offset

Posted: Wed May 06, 2015 12:43 pm
by 16573450
Hi could you send me the entire project to check, because it simply fails. I am wondering whether it comes from some misconfiguration at my side.
thanks

Re: x-axis title offset

Posted: Wed May 06, 2015 1:04 pm
by yeray
Hello,

Here it is:
testAnnotation.zip
(1.79 KiB) Downloaded 632 times
At designtime I only dropped into the form, aligned the chart to alClient and assigned FormCreate and Chart1BeforeDrawSeries events.