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
ValueIndex of TcursorTool
Hi Calou,
Here is how you could do it:
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;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
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?
I'm not sure to understand you. The index of the tool? But when you want to retrieve it, when it's clicked?
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
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:
Otherwise, if you want to know if your (known) Cursor tool is clicked when the chart is clicked, you could do as follows:
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;
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;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
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
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
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:
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;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |