Storing obejcts behind points, and getting the Z value

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
linkhrsys
Newbie
Newbie
Posts: 7
Joined: Mon Feb 28, 2005 5:00 am

Storing obejcts behind points, and getting the Z value

Post by linkhrsys » Thu Feb 23, 2006 3:44 pm

I have a situation where i am using a TTowerSeries with an X,Y,Z axis. When a user clicks a point in the chart i want to return an object associated with the point that has been clicked.

In essence i have a list of X values, and assigned to each X value is a list of Z values. When a user clicks on the chart i first get the X value point position and then use this to look up the Z values, but i am having problems looking up the Z value, i can not seem to get the current position of the depth axis (Z).

Is there an easier way to store an object behind a point, so when the bar is clicked it returns an object. Or alternatively how do i get the Z axis position and value?

linkhrsys
Newbie
Newbie
Posts: 7
Joined: Mon Feb 28, 2005 5:00 am

Post by linkhrsys » Fri Feb 24, 2006 10:46 am

I have knocked up a quick diagram to explain what i am trying to achieve. Please help.

Image

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 Feb 24, 2006 11:05 am

Hi linkhrsys,

You can try using a TNearestTool and something like the code below on TChart's OnMouseMove event.

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var index: Integer;
begin
  index:=ChartTool1.GetNearestPoint(Series1,X,Y);
  Chart1.Title.Text[0]:='X: '+FloatToStr(Series1.XValues[index])+
                        ', Y: '+FloatToStr(Series1.YValues[index])+
                        ', Z: '+FloatToStr(Series1.ZValues[index]);
end;
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

linkhrsys
Newbie
Newbie
Posts: 7
Joined: Mon Feb 28, 2005 5:00 am

Post by linkhrsys » Fri Feb 24, 2006 11:20 am

Thank you for your help, the solution works great :)

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 Feb 24, 2006 11:29 am

Excellent! I'm glad to hear that fits your needs.
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

linkhrsys
Newbie
Newbie
Posts: 7
Joined: Mon Feb 28, 2005 5:00 am

Post by linkhrsys » Thu Mar 02, 2006 9:13 am

After having used the solution you posted and fully testing it, we find it is very hard to select a bar using this method.

Is there no possible way that on mouseclick could return index of the bar being clicked on a 3d axis, instead of using the tool GetNearestPoint which is inacurrate. This would have to take into account if the bar being clicked is visible, and not another bar behind on the Y axis.

linkhrsys
Newbie
Newbie
Posts: 7
Joined: Mon Feb 28, 2005 5:00 am

Post by linkhrsys » Fri Mar 03, 2006 9:31 am

Any ideas Narcis? If this is not possible we will have to implement an alternative solution without the Z axis and using the ColorGrid.

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Wed Mar 08, 2006 12:01 pm

Hi,

how about using the following code :

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var ValueIndex: Integer;
ZPos: Integer;
begin
{ get 2d position }
ValueIndex := Series1.Clicked(X,Y);
if ValueIndex <> -1 then
begin
ZPos := Series1.CalcZPos(ValueIndex); { ZPosition for Canvas }
end;
end;

linkhrsys
Newbie
Newbie
Posts: 7
Joined: Mon Feb 28, 2005 5:00 am

Post by linkhrsys » Wed Mar 08, 2006 1:05 pm

Using this method the ValueIndex returned is -1 when clicking in a 3D chart

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Wed Mar 15, 2006 12:53 am

Hi,

yes, it could be for special case, note that TeeChart uses Y=Y(X,Z) and not more "usual" Z=Z(X,Y)).
This one is not an easy task. Determining X position (once you know the Z position) is easy. But determining Z position (depth axis) is a lot more difficult. We still haven't fully developed 3D<->2D transformation routines for this feature.

At the moment the only solution I can think of is the one I said to you, but this method could not give you 100% accurate results in special cases.

Post Reply