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