Page 1 of 1

Series Y value based on X position

Posted: Wed Nov 21, 2012 12:55 am
by 16564225
Hello everyone,

I have a simple line series graph. Y are values of pressure and X are time values in seconds.

I would like to get Y values based on X (mouse) cursor position. I don't want Y mouse cursor position values but the SERIES Y value based on mouse X position.

For example:

Mouse(2,2) -- series Y value at 2 = 5
Mouse(2,6) -- series Y value at 2 = 5
Mouse(2, 13) -- series Y value at 2 = 5


Best regards,
J

Re: Series Y value based on X position

Posted: Wed Nov 21, 2012 10:36 am
by narcis
Hi JoJu,

Yes, you can do something like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Series1.FillSampleValues;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  startY  : Integer;
  endY    : Integer;
  i       : Integer;
  index   : Integer;
  yVal    : Double;
begin
  startY:=Chart1.Axes.Left.IStartPos;
  endY:=Chart1.Axes.Left.IEndPos;

  for i:=startY to endY do
  begin
    index:=Series1.Clicked(X, i);
    if (index <> TeeNoPointClicked) then
    begin
      yVal:=Series1.YValues[index];
      Chart1.Title.Text[0]:=FloatToStr(yVal);
      break;
    end;
  end;

end;

Re: Series Y value based on X position

Posted: Wed Nov 21, 2012 2:14 pm
by 16564225
Thank you! That is exactly what I needed.

Keep on with the good work!