5,388
社区成员
发帖
与我相关
我的任务
分享
procedure DBChart1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
{ This procedure draws the crosshair lines }
Procedure DrawCross(AX,AY:Integer);
begin
With DBChart1,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
I : Integer;
Vx : Double;
AValueIndex : Integer;
TmpSeies : TChartSeries;
tmpX,tmpY,xpox:double;
begin
DBChart1.Repaint;
if (OldX<>-1) then
begin
DrawCross(OldX,OldY); { draw old crosshair }
OldX:=-1;
end;
{ check if mouse is inside Chart rectangle }
if PtInRect( DBChart1.ChartRect, Point(X-DBChart1.Width3D,Y+DBChart1.Height3D) ) then
begin
DrawCross(x,y); { draw crosshair at current position }
{ store old position }
OldX:=x;
OldY:=y;
Series1.GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor }
if tmpX > 0 then
begin
DBChart1.Canvas.Font.Color:=clRed;//字体颜色
DBChart1.Canvas.Font.Size := 14;
DBChart1.Canvas.Brush.Style := bsClear;//透明
Vx := Series1.YValues.Value[Trunc(tmpx)];
DBChart1.Canvas.TextOut(x+5,y-25,FloatToStr(Vx));
end;
end;
end;