Page 1 of 1

How to detect user double click on x axis area or Y axis are

Posted: Mon Sep 26, 2005 8:52 am
by 9235196
How to detect if user double click on x axis area or Y axis area?
Any event I can use?

Thank you

Posted: Mon Sep 26, 2005 9:00 am
by narcis
Hi Herman,

You can use TChart's OnClickAxis event.

Posted: Tue Sep 27, 2005 10:32 am
by 9235196
ummm but I want to detect it on double click event instead of just clicking.
And clickaxis seems to be work when i click precisely on the axis line, what if i click on area near the axis line (outside the axis for sure, not inside) but still have the same effect. Possible?

Posted: Tue Sep 27, 2005 11:15 am
by narcis
Hi Herman,
ummm but I want to detect it on double click event instead of just clicking.
Yes, but it's easier with some events which already provide mouse coordinates on their arguments list.
And clickaxis seems to be work when i click precisely on the axis line, what if i click on area near the axis line (outside the axis for sure, not inside) but still have the same effect. Possible?
Yes, you can do something like:

Code: Select all

procedure TForm1.Chart1DblClick(Sender: TObject);
var
  Top,Bottom,Left,Right: Integer;
  MousePos: TPoint;
begin
  Top:=Chart1.Axes.Left.IStartPos;
  Bottom:=Chart1.Axes.Left.IEndPos;
  Left:=Chart1.Axes.Left.PosAxis-30;
  Right:=Chart1.Axes.Left.PosAxis;

  MousePos:=Chart1.GetCursorPos;

  if ((MousePos.X>=Left) and (MousePos.X<=Right) and
      (MousePos.Y>=Top) and (MousePos.Y<=Bottom)) then
    Chart1.Title.Text[0]:='Left Axis Clicked!'
  else Chart1.Title.Text[0]:= IntToStr(Top)+', ' +
                          IntToStr(Bottom)+', ' +
                          IntToStr(Left)+', ' +
                          IntToStr(Right);
end;
or

Code: Select all

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Top,Bottom,Left,Right: Integer;
begin
  Top:=Chart1.Axes.Left.IStartPos;
  Bottom:=Chart1.Axes.Left.IEndPos;
  Left:=Chart1.Axes.Left.PosAxis-30;
  Right:=Chart1.Axes.Left.PosAxis;

  if ((X>=Left) and (X<=Right) and (Y>=Top) and (Y<=Bottom)) then
    Chart1.Title.Text[0]:='Left Axis Clicked!'
  else Chart1.Title.Text[0]:= IntToStr(Top)+', ' +
                          IntToStr(Bottom)+', ' +
                          IntToStr(Left)+', ' +
                          IntToStr(Right);
end;