Page 1 of 1
Failed to change the Annotation of TCursorTool
Posted: Wed May 28, 2014 11:23 pm
by 16566869
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.
Re: Failed to change the Annotation of TCursorTool
Posted: Thu May 29, 2014 11:25 am
by yeray
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);
}
Re: Failed to change the Annotation of TCursorTool
Posted: Thu May 29, 2014 6:40 pm
by 16566869
I changed to my text like following, but the Annotation is still the XValue...
Sender->AxisAnnotation->Text = "test";
Re: Failed to change the Annotation of TCursorTool
Posted: Thu May 29, 2014 6:41 pm
by 16566869
BTW, I am using the newest version(2014) for XE4 C++ Builder Firemonkey HD App.
Re: Failed to change the Annotation of TCursorTool
Posted: Fri May 30, 2014 8:35 am
by yeray
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;
}