Text position in TColorBandTool

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
JRadke
Newbie
Newbie
Posts: 10
Joined: Mon Oct 31, 2016 12:00 am

Text position in TColorBandTool

Post by JRadke » Thu Jan 12, 2017 9:36 am

Hi,

I have assigned a TColorBandTool to the bottom axis of a chart and want to change the text position of the StartLine to the left-top corner.
I've tried the following code:

Code: Select all

  with MyColorBandTool do begin
    StartLine.Annotation.Text := 'My text';
    StartLine.Annotation.Position := ppLeftTop; 
  end;
but the text is always positioned at the middle of the axis.

Is there a way to chance it?

Kind Regards
Juergen

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

Re: Text position in TColorBandTool

Post by Yeray » Fri Jan 13, 2017 10:39 am

Hello Juergen,

The TColorBandTool embeds two TColorLineTools, and the TColorLineTool embeds a TAnnotationTool. However, the Position property is designed to be used with the TAnnotationTool alone. In these embedded TAnnotationTools the chart calculates the position automatically.
If you want further customization, you should hide the embedded annotation, create an independent TAnnotationTool and reposition it at the TColorBandTool OnChanged event. Ie:

Code: Select all

var MyColorBand: TColorBandTool;
    MyStartAnnotation: TAnnotationTool;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.Visible:=False;
  Chart1.AddSeries(TLineSeries).FillSampleValues;

  MyColorBand:=Chart1.Tools.Add(TColorBandTool) as TColorBandTool;
  with MyColorBand do
  begin
    Axis:=Chart1.Axes.Bottom;
    StartValue:=15;
    EndValue:=20;
    OnChanged:=ColorBandChange;
  end;

  MyStartAnnotation:=Chart1.Tools.Add(TAnnotationTool) as TAnnotationTool;
  MyStartAnnotation.Text:='My text';

  Chart1.Draw;
  ColorBandChange(MyColorBand);
end;

procedure TForm1.ColorBandChange(Sender: TObject);
begin
  MyStartAnnotation.Shape.Left:=MyColorBand.Axis.CalcPosValue(MyColorBand.StartLine.Value);
  MyStartAnnotation.Shape.Top:=Chart1.ChartRect.Top;
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

JRadke
Newbie
Newbie
Posts: 10
Joined: Mon Oct 31, 2016 12:00 am

Re: Text position in TColorBandTool

Post by JRadke » Fri Jan 13, 2017 12:54 pm

Hello Yeray,

Thank you for your reply.
I will take your example code as template for my further work.

Kind regards
Juergen

Post Reply