Failed to change the Annotation of TCursorTool

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Failed to change the Annotation of TCursorTool

Post by elmec » Wed May 28, 2014 11:23 pm

We know that TCursorTool has "AxisAnnotatin->Text" property for annotation text.
But I failed to changed the text...when the TCursorTool moved, it changed to the X value (when the TCursorTool style is cssVertical)

Thanks in advance.

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

Re: Failed to change the Annotation of TCursorTool

Post by Yeray » Thu May 29, 2014 11:25 am

Hello,

EDIT:
I'm afraid I was wrong when I wrote the message below. The TCursorTool's OnChange event is fired too late: at the moment it is fired, both the TCursorTool and the AxisAnnotation have already been drawn.

----------------------------

I've tried this with Delphi 7 and C++Builder XE6 and it seems to work fine for me here with the following code.

Delphi:

Code: Select all

uses {...} TeeTools;
//...
  private
    { Private declarations }
    procedure CursorChange(Sender:TCursorTool; x,y:Integer; Const XValue,YValue:Double;
                           Series:TChartSeries; ValueIndex:Integer);
//...
uses Series;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Chart1.AddSeries(TLineSeries).FillSampleValues();

  with Chart1.Tools.Add(TCursorTool) as TCursorTool do
  begin
    AxisAnnotation.Visible:=true;
    Style:=cssVertical;
    OnChange:=CursorChange;
  end;

end;

procedure TForm1.CursorChange(Sender:TCursorTool; x,y:Integer; Const XValue,YValue:Double;
                       Series:TChartSeries; ValueIndex:Integer);
begin
  Sender.AxisAnnotation.Text:=FormatFloat('#0.##', XValue);
end;
C++Builder:
Unit1.h:

Code: Select all

//...
#include <VCLTee.Series.hpp>
#include <VCLTee.TeeTools.hpp>
//...
private:	// User declarations
	void __fastcall CursorChange(TCursorTool *Sender, Integer x, Integer y, Double XValue,
								 Double YValue, TChartSeries *Series, Integer ValueIndex);
Unit1.cpp:

Code: Select all

//...
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Chart1->View3D=false;
  Chart1->Legend->Visible=false;

  Chart1->AddSeries(new TLineSeries(this))->FillSampleValues();

  TCursorTool *cursor1=new TCursorTool(this);
  Chart1->Tools->Add(cursor1);
  cursor1->AxisAnnotation->Visible=true;
  cursor1->Style=cssVertical;
  cursor1->OnChange=CursorChange;
}

void __fastcall TForm1::CursorChange(TCursorTool *Sender, Integer x, Integer y, Double XValue,
								 Double YValue, TChartSeries *Series, Integer ValueIndex)
{
  Sender->AxisAnnotation->Text=FormatFloat("#0.##", XValue);
}
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

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: Failed to change the Annotation of TCursorTool

Post by elmec » Thu May 29, 2014 6:40 pm

I changed to my text like following, but the Annotation is still the XValue...
Sender->AxisAnnotation->Text = "test";
Attachments
Cursor.png
Cursor.png (3.6 KiB) Viewed 13621 times

elmec
Advanced
Posts: 129
Joined: Mon Aug 26, 2013 12:00 am

Re: Failed to change the Annotation of TCursorTool

Post by elmec » Thu May 29, 2014 6:41 pm

BTW, I am using the newest version(2014) for XE4 C++ Builder Firemonkey HD App.

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

Re: Failed to change the Annotation of TCursorTool

Post by Yeray » Fri May 30, 2014 8:35 am

Hello,

I'm afraid I was wrong when I wrote the last post. I've edited it adding a line where clarifies I was wrong when I made the assumption in that post.
Yeray wrote:The TCursorTool's OnChange event is fired too late: at the moment it is fired, both the TCursorTool and the AxisAnnotation have already been drawn.
So I'm afraid the only way I can think you could change the annotation text at TCursorTool's OnChange event is using an independent TAnnotationTool instead of the TCursorTool's AxisAnnotation. Ie:

Unit1.h:

Code: Select all

//...
#include <FMXTee.Series.hpp>
#include <FMXTee.Tools.hpp>
//...
private:   // User declarations
   void __fastcall CursorChange(TCursorTool *Sender, Integer x, Integer y, Double XValue,
						 Double YValue, TChartSeries *Series, Integer ValueIndex);
   TAnnotationTool * myAnnotation;
Unit1.cpp:

Code: Select all

//...
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Chart1->View3D=false;
  Chart1->Legend->Visible=false;

  Chart1->AddSeries(new TLineSeries(this))->FillSampleValues();

  TCursorTool *cursor1=new TCursorTool(this);
  Chart1->Tools->Add(cursor1);
  cursor1->Style=cssVertical;
  cursor1->OnChange=CursorChange;

  myAnnotation=new TAnnotationTool(this);
  Chart1->Tools->Add(myAnnotation);
}

void __fastcall TForm1::CursorChange(TCursorTool *Sender, Integer x, Integer y, Double XValue,
						 Double YValue, TChartSeries *Series, Integer ValueIndex)
{
  myAnnotation->Text=FormatFloat("#0.##", XValue);
  int tmp=(myAnnotation->Width==0) ? 10 : myAnnotation->Width*0.5;

  myAnnotation->Left=Chart1->Axes->Bottom->CalcPosValue(XValue)-tmp;
  tmp=Chart1->Axes->Bottom->PosAxis;
  if (Chart1->Axes->Bottom->Axis->Visible) {
	tmp+=Chart1->Axes->Bottom->Axis->Width;
  }
  myAnnotation->Top=tmp;
}
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