procedure DBChart1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var
I : Integer;
AValueIndex : Integer;
TmpSeies : TChartSeries;
tmpX,tmpY:double;
begin
for I := 0 to TDBChart(Sender).SeriesList.Count - 1 do
begin
TmpSeies := TDBChart(Sender).SeriesList.Items[I];
if TmpSeies = Series1 then
begin
AValueIndex := Series1.GetCursorValueIndex;
if AValueIndex > -1 then
begin
Series1.GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor }
DBChart1.Canvas.Font.Color:=clRed;//字體顏色
DBChart1.Canvas.Font.Size := 14;
DBChart1.Canvas.Brush.Style := bsClear;//透明
DBChart1.Canvas.TextOut(x+5,y-25,Series1.GetVertAxis.LabelValue(tmpY));
end
else
DBChart1.Repaint;
end;
end;
end;
完善一部分功能
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;