Hello all,
I have a TChart with several TLineSeries added by code. I need to use the TNearestTool but it should "look" at the series that is closer to the mouse. Can anyone give me a hint on how to do that?
Regards
P.S. TeeChart Pro 7.0
Is this possible?
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi johnnix,
Each TNearestTool is intended to have a series assigned. However, to achieve what you request you can do something like this:
Each TNearestTool is intended to have a series assigned. However, to achieve what you request you can do something like this:
Code: Select all
uses Series, Math;
procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
for i:=0 to 4 do
begin
Chart1.AddSeries(TLineSeries.Create(self));
Chart1[i].FillSampleValues();
end;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var i, tmpIndex, SeriesIndex: Integer;
tmpDistance, currDistance: Real;
begin
tmpDistance:=sqrt(Power(Chart1.Width,2)+ //tmpDistance is chart's diagonal,
Power(Chart1.Height,2)); //which is the max. distance possible
SeriesIndex:=-1;
for i:=0 to Chart1.SeriesCount-1 do
begin
tmpIndex:=ChartTool1.GetNearestPoint(Chart1[i],X,Y);
currDistance:=Abs(Distance(Chart1[i].CalcXPos(tmpIndex),
Chart1[i].CalcYPos(tmpIndex), X, Y));
if (currDistance < tmpDistance) then
begin
SeriesIndex:=i;
tmpDistance:=currDistance;
end;
end;
if SeriesIndex<>-1 then
ChartTool1.Series:=Chart1[SeriesIndex];
end;
function TForm1.Distance(XPos, YPos, X, Y: Integer): Real;
begin
Result:=sqrt(Power(XPos-X,2)+Power(YPos-Y,2));
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |