Page 1 of 1
ValueIndex of TcursorTool
Posted: Tue May 05, 2009 2:03 pm
by 10050873
Hello,
I want to know the value index of a TcursorTool without moving it with the mouse (snap=true)
Is it possible?
Thank you
Regards
Posted: Tue May 05, 2009 2:22 pm
by yeray
Hi Calou,
Here is how you could do it:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var Index: Integer;
begin
Index := Series1.Clicked(Chart1.Axes.Bottom.CalcXPosValue(ChartTool1.XValue),
Chart1.Axes.Left.CalcYPosValue(ChartTool1.YValue));
Chart1.Title.Text.Text := IntToStr(Index);
end;
Posted: Tue May 05, 2009 2:25 pm
by yeray
Hi Calou,
I'm not sure to understand you. The index of the tool? But when you want to retrieve it, when it's clicked?
Posted: Tue May 05, 2009 2:38 pm
by 10050873
Yes i want the valueindex of the tool to display series values when the chart is shown and before the user move the cursor
Posted: Tue May 05, 2009 3:31 pm
by yeray
Hi Calou,
I'm afraid that I'm still not sure to understand what exactly you want to do. If you have several tools and you want to know which one is the cursor tool you could do:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var i, CursorIndex: Integer;
begin
for i:=0 to Chart1.Tools.Count-1 do
begin
if (Chart1.Tools[i] is TCursorTool) then
begin
CursorIndex := i;
break;
end;
end;
Chart1.Title.Text.Text := IntToStr(CursorIndex);
end;
Otherwise, if you want to know if your (known) Cursor tool is clicked when the chart is clicked, you could do as follows:
Code: Select all
var MouseX, MouseY: Integer;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
MouseX := X;
MouseY := Y;
end;
procedure TForm1.Chart1Click(Sender: TObject);
begin
if (ChartTool1.Clicked(MouseX,MouseY) = TCursorClicked(1)) or
(ChartTool1.Clicked(MouseX,MouseY) = TCursorClicked(2)) or
(ChartTool1.Clicked(MouseX,MouseY) = TCursorClicked(3)) then
Chart1.Title.Text.Text := 'Cursor Tool clicked'
else
Chart1.Title.Text.Text := 'Cursor Tool NOT clicked';
end;
Posted: Tue May 05, 2009 4:14 pm
by 10050873
that you write in your first answer is good for me. However I have tried your code but index always = -1 because I think i look at ChartTool1.XValue and ChartTool1.YValue before the chart is drawn and their values =0
That i want to do is when the chart is visible i want to print the value of the series where the cursor is. So i try to know the valueindex of the series where the cursor is at the beginning.
I hope it is more clear
Posted: Wed May 06, 2009 7:40 am
by yeray
Hi Calou,
If I understand fine, you probably only need to force a chart draw (Chart1.Draw; ). Here is a simple example of what I understood:
Code: Select all
uses series, TeeTools;
procedure TForm1.FormCreate(Sender: TObject);
var i, CursorIndex, SeriesIndex: Integer;
begin
Chart1.View3D := false;
CursorIndex := -1;
SeriesIndex := -1;
for i:=0 to 3 do
begin
Chart1.AddSeries(TPointSeries.Create(self));
Chart1[i].FillSampleValues(25);
end;
Chart1.Tools.Add(TAnnotationTool.Create(self));
Chart1.Tools.Add(TDragMarksTool.Create(self));
Chart1.Tools.Add(TAnnotationTool.Create(self));
Chart1.Tools.Add(TCursorTool.Create(self));
for i:=0 to Chart1.Tools.Count-1 do
if (Chart1.Tools[i] is TCursorTool) then
begin
CursorIndex := i;
break;
end;
(Chart1.Tools[CursorIndex] as TCursorTool).Series := Chart1[2];
(Chart1.Tools[CursorIndex] as TCursorTool).Snap := true;
for i:=0 to Chart1.SeriesCount-1 do
if (Chart1.Tools[CursorIndex] as TCursorTool).Series = Chart1[i] then
begin
SeriesIndex := i;
break;
end;
Chart1.Draw;
with (Chart1.Tools[CursorIndex] as TCursorTool) do
Chart1.Title.Text.Text := 'SeriesIndex: ' + IntToStr(SeriesIndex) + ' XValue: ' + FloatToStr(XValue) + ' YValue: ' + FloatToStr(YValue);
end;