How to set CursorTool Annotation Text

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Technicon
Newbie
Newbie
Posts: 43
Joined: Thu Aug 11, 2016 12:00 am
Contact:

How to set CursorTool Annotation Text

Post by Technicon » Tue Aug 30, 2016 6:44 am

Hi,

I try to set my own text int CursorTool Annotation like this

Code: Select all

pTCursorTool->AxisAnnotation->Text = "L " + TDateTime(XValue).FormatString("yyyy-mm-dd hh:nn");
in TCursorTool.OnChange event, but my text is always overwritten by some defaults.
I try do this in AxisAnnotation->OnBeforeDraw, but this doesn't work too.
Any idea how to do this properly?

I also don't know how to add "Cursor.Annotation.Text.Format.Children" form code :(

Regards,
Grzegorz

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

Re: How to set CursorTool Annotation Text

Post by Yeray » Tue Aug 30, 2016 8:45 am

Hello,

Here it is a Delphi example:

Code: Select all

  with Chart1.Tools.Add(TCursorTool) as TCursorTool do
  begin
    AxisAnnotation.Visible:=true;
    with AxisAnnotation.Shape.Children.Add do
    begin
      TCustomTextShape(Shape).Text:='Child 1';
    end;
  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

Technicon
Newbie
Newbie
Posts: 43
Joined: Thu Aug 11, 2016 12:00 am
Contact:

Re: How to set CursorTool Annotation Text

Post by Technicon » Tue Aug 30, 2016 10:07 am

Hi,

Thank You. The code snippet works fine.
Any chance to answer for the first question?

Regards,
Grzegorz

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

Re: How to set CursorTool Annotation Text

Post by Yeray » Tue Aug 30, 2016 11:04 am

Hello,

The text in the AxisAnnotation is reset when the Cursor Tool is redrawn.
However, you could still use OnGetAxisLabel event as follows:

Code: Select all

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
var tmp, tmpR : String;
begin
  if Sender = Chart1.Axes.Bottom then
  begin
    if Sender.IsDateTime then
    begin
      if Sender.DateTimeFormat='' then tmp:=DateTimeDefaultFormat(Sender.Maximum-Sender.Minimum)
                                  else tmp:=Sender.DateTimeFormat;

      DateTimeToString(tmpR,tmp,ChartTool1.XValue);
    end
    else
      tmpR:=FormatFloat(Sender.AxisValuesFormat,ChartTool1.XValue);

    if tmpR = LabelText then
      LabelText:='L ' + FormatDateTime('yyyy-mm-dd hh:nn', ChartTool1.XValue);
  end;
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

Technicon
Newbie
Newbie
Posts: 43
Joined: Thu Aug 11, 2016 12:00 am
Contact:

Re: How to set CursorTool Annotation Text

Post by Technicon » Thu Sep 01, 2016 11:34 am

Hi,

Thank You for the code snippet.

Regards,
Grzegorz

Post Reply