例如在Tchart上有一组柱状图形,横坐标是时间X,纵坐标是数值Y,当鼠标放到图像上时,如何在鼠标旁边显示横纵坐标的数值x,y?
请各位帮帮忙!

解决方案 »

  1.   

    procedure TCrossHairForm.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);  { This procedure draws the crosshair lines }
      Procedure DrawCross(AX,AY:Integer);
      begin
        With Chart1,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( Chart1.ChartRect, Point(X-Chart1.Width3D,Y+Chart1.Height3D)  ) then
      begin
        DrawCross(x,y);  { draw crosshair at current position }
        { store old position }
        OldX:=x;
        OldY:=y;
        { set label text }
        With LineSeries1 do
        begin
          GetCursorValues(tmpX,tmpY);  { <-- get values under mouse cursor }
          Label1.Caption:=GetVertAxis.LabelValue(tmpY)+
                          ' '+
                          GetHorizAxis.LabelValue(tmpX);
        end;
      end;
    end;
      

  2.   


    此方法在Chart上的任意点都会显示坐标 要是有方法只在有图的地方显示就好了 哈哈 
      

  3.   

    我自己弄到了,原来是在Tchart中的tools里面,谢谢各位