Custom axes and the metrics

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
ibauer
Newbie
Newbie
Posts: 35
Joined: Thu Mar 31, 2005 5:00 am
Location: Czech Republic

Custom axes and the metrics

Post by ibauer » Fri Nov 02, 2007 11:43 am

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!
Ivo Bauer [OZM Research]

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Nov 02, 2007 11:50 am

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!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

ibauer
Newbie
Newbie
Posts: 35
Joined: Thu Mar 31, 2005 5:00 am
Location: Czech Republic

Post by ibauer » Fri Nov 02, 2007 12:52 pm

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;
Ivo Bauer [OZM Research]

Post Reply