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.
Failed to change the Annotation of TCursorTool
Re: Failed to change the Annotation of TCursorTool
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:
C++Builder:
Unit1.h:
Unit1.cpp:
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;
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);
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Failed to change the Annotation of TCursorTool
I changed to my text like following, but the Annotation is still the XValue...
Sender->AxisAnnotation->Text = "test";
Sender->AxisAnnotation->Text = "test";
- Attachments
-
- Cursor.png (3.6 KiB) Viewed 13440 times
Re: Failed to change the Annotation of TCursorTool
BTW, I am using the newest version(2014) for XE4 C++ Builder Firemonkey HD App.
Re: Failed to change the Annotation of TCursorTool
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.
Unit1.h:
Unit1.cpp:
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.
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: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.
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;
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |