Page 1 of 1
How to set CursorTool Annotation Text
Posted: Tue Aug 30, 2016 6:44 am
by 16578912
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
Re: How to set CursorTool Annotation Text
Posted: Tue Aug 30, 2016 8:45 am
by yeray
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;
Re: How to set CursorTool Annotation Text
Posted: Tue Aug 30, 2016 10:07 am
by 16578912
Hi,
Thank You. The code snippet works fine.
Any chance to answer for the first question?
Regards,
Grzegorz
Re: How to set CursorTool Annotation Text
Posted: Tue Aug 30, 2016 11:04 am
by yeray
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;
Re: How to set CursorTool Annotation Text
Posted: Thu Sep 01, 2016 11:34 am
by 16578912
Hi,
Thank You for the code snippet.
Regards,
Grzegorz