teechart 已知 X轴的值,求 曲线 Y轴的值

jiangzs188136923 2013-09-17 05:16:05
一个tchart图表,上面有三线曲线,共用X轴,在鼠标移动时,画了一条 竖线,这时通过mousemove可以获取 点X的值,请问在mousemove过程中,如何 获取三线曲线对应的Y轴值 ???
...全文
264 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaojian365 2013-10-21
  • 打赏
  • 举报
回复
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;
xiaojian365 2013-10-21
  • 打赏
  • 举报
回复
我也遇到这个问题,请问楼主解决了吗?
simonhehe 2013-09-18
  • 打赏
  • 举报
回复
如果已有的曲线是通过公式计算suode,则依赖公式可以获得任一X点的y值. 其他情况下, 可以通过x点左右两个已知坐标点, 计算当前x点的y点 如3条线 A x:0, y:0; x:1, y:2; B x:0, y:0; x:1, y:4; C x:0, y:0; x:1, y:8; 求X:0.5时, y值, 解方程即可

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧