teechart中取点的坐标值的问题,十万火急!!高分相赠。。(100分)

Q

qgqg

Unregistered / Unconfirmed
GUEST, unregistred user!
我在dbCHART控件上动态画了几条曲线,当我用鼠标点击dbCHART控件时会有一条竖线随鼠标移动;
同时要在一个LABEL控件上显示横坐标及对应此横坐标的几条曲线的纵坐标值,应该怎样做?
用GetCursorValues()很容易得到横坐标的值,但相应的纵坐标值不知怎样得到?请各位高手指点,
不甚感谢!
 
procedure TFrmMain.DBChart1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
tmpDate, tmpValue : Double ;
tmpIndex : Integer;
i : Integer;
sIndex : Integer;
pCount : Integer;
tmpDoub : string ;
begin
if IsMouseMoving then exit;

IsMouseMoving := True;
sIndex := 0;
pCount := 0;
for i :=0 to 3 do
begin
if DBChart1.Series.Labels.Count > pCount then
begin
pCount := DBChart1.Series.Labels.Count;
sIndex := i;
end;
end;

DBChart1.Series[sIndex].GetCursorValues(tmpDate,tmpValue);
tmpIndex := Round(tmpDate);
IsMouseMoving := False;
if pCount=0 then exit;
if (tmpIndex < 0) then tmpIndex:=0;
if (tmpIndex >= pCount) then tmpIndex:=pCount-1;
tmpDoub := FormatFloat('0.###0',tmpValue) ;
StatusBar1.Panels[1].Text:= '时间: '+ DBChart1.Series[sIndex].XLabel[tmpIndex]
+' 数值:' + tmpDoub ;

end ;


{ 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 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( 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;
{ set label text }
{With DBChart1.Series[0] do
begin
GetCursorValues(tmpX,tmpY); { <-- get values under mouse cursor }
{ Label1.Caption:=GetVertAxis.LabelValue(tmpY)+
' '+
GetHorizAxis.LabelValue(tmpX);}
//------------------------------------------------------------------------------
 
其中用{}注释掉的代码用来实现 “当我用鼠标点击dbCHART控件时会有一条竖线随鼠标移动”
的功能!我正好有这方面的代码 真是巧!
 
呵呵  代码需要自己整理一下 有点乱 不过功能没有问题的 我都试过了!
 
不知道你是甚么意思。
Teechart自己不是有一个方法么?
procedure TFormMain.Chart_Res1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
Var
p:TPoint;
XValue,YValue:Double;
begin
P.x:=x;
P.y:=y;
Xvalue:=ChartT_Res.ScreenPoint(P).x; //这里将屏幕坐标转化为物理坐标
YValue:=ChartT_Res.ScreenPoint(p).y;
With Statusbar1 do //我的是显示在状态条上的
Begin
P_Count:=Panels.Count;
Panels[P_Count-1].Text:=Format('XValue: %8.4f, YValue: %8.2f',
[XValue,YValue])
End;
end;
 
呵呵,知道了,我用的是商用的Teechart组件
ChartT_Res:TDrawLineTool
是画线工具。
不知道Delphi自带的Teechart组件中有没有
 
cwmdelpher,韧峰二位兄弟,
你们好!
非常感谢您的回复。我测试了一下,得到的值是鼠标当前位置(X,Y)的值,
而且X值不会变,而我想得到的是鼠标所在位置X的值与对应的组成曲线的点的Y值,
我的X轴不是时间,而是光波长纳米。(我在DBchart上画了2条曲线,要取2条曲线的Y值)。
为了感谢你们,各给50分以示谢意。希望二位能再帮帮我。因为我是各初学者,很多地方
不懂。还望不吝赐教。
谢谢!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
892
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
顶部