参考这个 procedure TForm1.MoveData(var MyLable:TLabel;MyChart:TDBChart;X,Y:integer); Var tmpX,tmpY:Double; begin { check if mouse is inside Chart rectangle } if PtInRect( MyChart.ChartRect, Point(X-MyChart.Width3D,Y+MyChart.Height3D) ) then begin { set label text } With MyChart.Series[0] do begin GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor } MyLable.Caption:=GetVertAxis.LabelValue(tmpY); // 这个是Y轴值 // GetHorizAxis.LabelValue(tmpX); // 这个是X轴值 end; end; end;procedure TForm1.DBChart1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer); begin MoveData(Label8,DbChart1,x,y); end;
声明 var Mark: TSeriesMarksStyle 让 Mark:=smsLabel,smsPercent,smsvalue等
我刚写过这个
procedure TForm1.MoveData(var MyLable:TLabel;MyChart:TDBChart;X,Y:integer);
Var tmpX,tmpY:Double;
begin
{ check if mouse is inside Chart rectangle }
if PtInRect( MyChart.ChartRect, Point(X-MyChart.Width3D,Y+MyChart.Height3D) ) then
begin
{ set label text }
With MyChart.Series[0] do
begin
GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor }
MyLable.Caption:=GetVertAxis.LabelValue(tmpY); // 这个是Y轴值
// GetHorizAxis.LabelValue(tmpX); // 这个是X轴值
end;
end;
end;procedure TForm1.DBChart1MouseMove(Sender: TObject; Shift: TShiftState;
X,Y: Integer);
begin
MoveData(Label8,DbChart1,x,y);
end;