problems with TNearestTool and TLineSeries
Posted: Tue Jun 26, 2007 8:51 am
Hi all,
I'm trying to use the TNearestTool to work out the time (x value) of the point (on a TLineSeries) closest to the mouse. When the user clicks a button, a nearest tool is created:
As they move their mouse around, the TNearestTool snaps to the closest point correctly. Then when they double-click, I have this code:
The problem is that GetNearestPoint does not seem return the correct index value. It's always at least 2 or three series points out, sometimes as many as 10 (which can be up to an hour on the chart).
Has anyone else seen this? Am I doing anything noticeably wrong?
Cheers,
Andrew
I'm trying to use the TNearestTool to work out the time (x value) of the point (on a TLineSeries) closest to the mouse. When the user clicks a button, a nearest tool is created:
Code: Select all
TNearestTool *nearTool = new TNearestTool(TrendChart);
TrendChart->Tools->Add(nearTool);
nearTool->LinePen->Color = clBlack;
nearTool->LinePen->Width = 2;
nearTool->Brush->Color = clRed;
nearTool->Pen->Color = clRed;
nearTool->Size = 5;
nearTool->Series = series;
nearTool->Active = true;
Code: Select all
for (int i=0; i < TrendChart->Tools->Count; i++)
{
//Find the nearest tool tool
if ( dynamic_cast<TNearestTool*>(TrendChart->Tools->Items[i]) != 0 )
{
TNearestTool *nearTool = (TNearestTool*)TrendChart->Tools->Items[i];
TDateTime tdtTime = nearTool->Series->XValue[nearTool->GetNearestPoint(__classid(TLineSeries), nearTool->Series, Mouse->CursorPos.x, Mouse->CursorPos.y)];
//Etc
Has anyone else seen this? Am I doing anything noticeably wrong?
Cheers,
Andrew