Page 1 of 1

How to add Text to annotation of ColorLineTool

Posted: Tue Aug 12, 2025 8:38 am
by 16594956
Hello TeeChart Team,

How can I add (prefix) some text to the numerical output (Annotation) shown of the TColorLineTool?
I tried to change the Text in the OnDragLine Event like:

Code: Select all

procedure TfrmXYPlot.XYLimitDragLine(Sender: TColorLineTool);
begin
  Sender.Annotation.Text := 'XY Limit: ' + Sender.Value.ToString;
end;
But that text doesn't show up?
ColorLineToolAnnotation.png
ColorLineToolAnnotation.png (72.55 KiB) Viewed 3335 times
Best regards,

Thomas

Re: How to add Text to annotation of ColorLineTool

Posted: Mon Aug 18, 2025 2:22 pm
by yeray
Hello Thomas,

Try setting AnnotationValue to False.

Re: How to add Text to annotation of ColorLineTool

Posted: Mon Aug 18, 2025 5:39 pm
by 16594956
Hello Yeray,

Thanks, that works fine now!

Re: How to add Text to annotation of ColorLineTool

Posted: Tue Aug 19, 2025 8:56 am
by 16594956
Hello,
The 2 lines produce 4 quadrants. Is it possible to draw one of the quadrants with a different background color?.
Actually the left/bottom one.
SNRvsWPercentQuadrant.png
4 Quadrants
SNRvsWPercentQuadrant.png (194.32 KiB) Viewed 1831 times

Re: How to add Text to annotation of ColorLineTool

Posted: Tue Aug 19, 2025 9:20 am
by yeray
Hello,

Assuming you know you have those ColorLine tools, you can use them to calculate the rectangle and draw it at OnBeforeDrawAxes event. Ie:
quadrant.png
quadrant.png (16.71 KiB) Viewed 1826 times

Code: Select all

uses Chart, Series, TeeTools;

var
  Chart1: TChart;
  HorizLine,
  VertLine: TColorLineTool;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1:=TChart.Create(Self);

  with Chart1 do
  begin
    Parent:=Self;
    Align:=alClient;
    Color:=clWhite;
    Gradient.Visible:=False;
    Walls.Back.Color:=clWhite;
    Walls.Back.Gradient.Visible:=False;
    Legend.Hide;
    View3D:=False;

    AddSeries(TPointSeries).FillSampleValues;

    HorizLine:=TColorLineTool(Tools.Add(TColorLineTool));
    with HorizLine do
    begin
      Axis:=Axes.Left;
      Value:=Series[0].YValues.MinValue + Series[0].YValues.Range / 2;
    end;

    VertLine:=TColorLineTool(Tools.Add(TColorLineTool));
    with VertLine do
    begin
      Axis:=Axes.Bottom;
      Value:=Series[0].XValues.MinValue + Series[0].XValues.Range / 2;
    end;

    OnBeforeDrawAxes:=BeforeDrawAxes;

    Draw;
  end;
end;

procedure TForm1.BeforeDrawAxes(Sender: TObject);
var rect: TRect;
begin
  if not Assigned(VertLine) or not Assigned(HorizLine) then
     Exit;

  rect.Left:=Chart1.Axes.Left.PosAxis;
  rect.Right:=Chart1.Axes.Bottom.CalcPosValue(VertLine.Value);
  rect.Bottom:=Chart1.Axes.Bottom.PosAxis;
  rect.Top:=Chart1.Axes.Left.CalcPosValue(HorizLine.Value);

  Chart1.Canvas.Brush.Color:=clRed;
  Chart1.Canvas.Brush.Transparency:=200;
  Chart1.Canvas.Rectangle(rect);
end;

Re: How to add Text to annotation of ColorLineTool

Posted: Wed Aug 20, 2025 5:54 am
by 16594956
Thanks, Yeray, this works like a Charm, perfect!
Just this doesn't compile under VCL:

Code: Select all

 Chart1.Canvas.Brush.Transparency:=200;
I think thats maybe FMX only?

Re: How to add Text to annotation of ColorLineTool

Posted: Wed Aug 20, 2025 7:09 am
by yeray
Hello,

Oups that was a spoiler of a new functionality for the next release.
Currently, to draw transparent shapes you need manually call BeginBlending and EndBlending. Ie:

Code: Select all

uses Chart, Series, TeeTools, TeCanvas;

//...

procedure TForm1.BeforeDrawAxes(Sender: TObject);
var
  rect: TRect;
  blend: TTeeBlend;
begin
  //...

  Chart1.Canvas.Brush.Color:=clRed;
  blend:=Chart1.Canvas.BeginBlending(rect, 80);
  Chart1.Canvas.Rectangle(rect);
  Chart1.Canvas.EndBlending(blend);
end;