Page 1 of 1

Custom axes and the metrics

Posted: Fri Nov 02, 2007 11:43 am
by 9341477
Hi,

I've got a chart that has a bottom (time) axis and a couple of vertical custom axes. I need your help to be able to achieve the following:

1) Given the mouse cursor position, determine which vertical axis the mouse is over at the moment so that I can calculate the corresponding coordinates. Normally, I would use something like Chart.LeftAxis.CalcPosPoint() but now I can't since I don't know which axis is under the mouse.

2) Determine bottom-most and top-most pixels of every custom axis. For a custom painting I need to know the boundary of each custom axis. Normally, I would use Chart.ChartRect.Bottom and Chart.ChartRect.Top if there was just only one left axis, but now it isn't.

Thanks in advance!

Posted: Fri Nov 02, 2007 11:50 am
by narcis
Hi Ivo,

Find below the answers to your questions:

1. You can use axes clicked method like this:

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var i: Integer;
begin
  for i:=0 to Chart1.CustomAxes.Count -1 do
  begin
    if Chart1.CustomAxes.Items[i].Clicked(X,Y) then
    begin
      //write your code here.
    end;
  end;
end;
2. Yes, you can use Chart1.CustomAxes.Items.IStartPos and Chart1.CustomAxes.Items.IEndPos.

Hope this helps!

Posted: Fri Nov 02, 2007 12:52 pm
by 9341477
Hi NarcĂ­s,

The IStartPos and IEndPos were exactly the properties I was after. Thanks for your advice! Regarding your first response, I have realized that I was asking a wrong question. I actually wanted to know if the point under the mouse cursor lies in a band/rectange whose boundary is determined by given horizontal and vertical axis. Here is an hit-test routine I have just written (thanks to your suggestion) along with some example of the usage:

Code: Select all

uses
  Math;

function PointInBand(X, Y: Integer; AHorzAxis, AVertAxis: TChartAxis): Boolean;
begin
  Result := InRange(X, AHorzAxis.IStartPos, AHorzAxis.IEndPos) and
    InRange(Y, AVertAxis.IStartPos, AVertAxis.IEndPos);
end;

Code: Select all

if PointInBand(X, Y, Chart.BottomAxis, Chart.CustomAxes[0]) then
begin
  // do something
end
else if PointInBand(X, Y, Chart.BottomAxis, Chart.LeftAxis) then
begin
  // do something
end;