procedure TCrossHairForm.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); { This procedure draws the crosshair lines } Procedure DrawCross(AX,AY:Integer); begin With Chart1,Canvas do begin Pen.Color:=CrossHairColor; Pen.Style:=CrossHairStyle; Pen.Mode:=pmXor; Pen.Width:=1; MoveTo(ax,ChartRect.Top-Height3D); LineTo(ax,ChartRect.Bottom-Height3D); MoveTo(ChartRect.Left+Width3D,ay); LineTo(ChartRect.Right+Width3D,ay); end; end;Var tmpX,tmpY:Double; begin if (OldX<>-1) then begin DrawCross(OldX,OldY); { draw old crosshair } OldX:=-1; end; { check if mouse is inside Chart rectangle } if PtInRect( Chart1.ChartRect, Point(X-Chart1.Width3D,Y+Chart1.Height3D) ) then begin DrawCross(x,y); { draw crosshair at current position } { store old position } OldX:=x; OldY:=y; { set label text } With LineSeries1 do begin GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor } Label1.Caption:=GetVertAxis.LabelValue(tmpY)+ ' '+ GetHorizAxis.LabelValue(tmpX); end; end; end;
Y: Integer); { This procedure draws the crosshair lines }
Procedure DrawCross(AX,AY:Integer);
begin
With Chart1,Canvas do
begin
Pen.Color:=CrossHairColor;
Pen.Style:=CrossHairStyle;
Pen.Mode:=pmXor;
Pen.Width:=1;
MoveTo(ax,ChartRect.Top-Height3D);
LineTo(ax,ChartRect.Bottom-Height3D);
MoveTo(ChartRect.Left+Width3D,ay);
LineTo(ChartRect.Right+Width3D,ay);
end;
end;Var tmpX,tmpY:Double;
begin
if (OldX<>-1) then
begin
DrawCross(OldX,OldY); { draw old crosshair }
OldX:=-1;
end; { check if mouse is inside Chart rectangle }
if PtInRect( Chart1.ChartRect, Point(X-Chart1.Width3D,Y+Chart1.Height3D) ) then
begin
DrawCross(x,y); { draw crosshair at current position }
{ store old position }
OldX:=x;
OldY:=y;
{ set label text }
With LineSeries1 do
begin
GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor }
Label1.Caption:=GetVertAxis.LabelValue(tmpY)+
' '+
GetHorizAxis.LabelValue(tmpX);
end;
end;
end;
此方法在Chart上的任意点都会显示坐标 要是有方法只在有图的地方显示就好了 哈哈