x-axis title offset

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
cssesuc
Newbie
Newbie
Posts: 44
Joined: Wed Apr 08, 2015 12:00 am

x-axis title offset

Post by cssesuc » Mon May 04, 2015 9:45 am

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
thanks,
Nabil Ghodbane (PhD. Habil)

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

Re: x-axis title offset

Post by Yeray » Mon May 04, 2015 2:38 pm

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;
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

cssesuc
Newbie
Newbie
Posts: 44
Joined: Wed Apr 08, 2015 12:00 am

Re: x-axis title offset

Post by cssesuc » Mon May 04, 2015 4:36 pm

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

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

Re: x-axis title offset

Post by Yeray » Tue May 05, 2015 9:20 am

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.
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

cssesuc
Newbie
Newbie
Posts: 44
Joined: Wed Apr 08, 2015 12:00 am

Re: x-axis title offset

Post by cssesuc » Wed May 06, 2015 9:20 am

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
thanks,
Nabil Ghodbane (PhD. Habil)

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

Re: x-axis title offset

Post by Yeray » Wed May 06, 2015 10:01 am

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;
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

cssesuc
Newbie
Newbie
Posts: 44
Joined: Wed Apr 08, 2015 12:00 am

Re: x-axis title offset

Post by cssesuc » Wed May 06, 2015 12:43 pm

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
thanks,
Nabil Ghodbane (PhD. Habil)

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

Re: x-axis title offset

Post by Yeray » Wed May 06, 2015 1:04 pm

Hello,

Here it is:
testAnnotation.zip
(1.79 KiB) Downloaded 598 times
At designtime I only dropped into the form, aligned the chart to alClient and assigned FormCreate and Chart1BeforeDrawSeries events.
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

Post Reply