Page 1 of 1

Text position in TColorBandTool

Posted: Thu Jan 12, 2017 9:36 am
by 16479503
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

Re: Text position in TColorBandTool

Posted: Fri Jan 13, 2017 10:39 am
by yeray
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;

Re: Text position in TColorBandTool

Posted: Fri Jan 13, 2017 12:54 pm
by 16479503
Hello Yeray,

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

Kind regards
Juergen