Page 1 of 1

Storing obejcts behind points, and getting the Z value

Posted: Thu Feb 23, 2006 3:44 pm
by 9341105
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?

Posted: Fri Feb 24, 2006 10:46 am
by 9341105
I have knocked up a quick diagram to explain what i am trying to achieve. Please help.

Image

Posted: Fri Feb 24, 2006 11:05 am
by narcis
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;

Posted: Fri Feb 24, 2006 11:20 am
by 9341105
Thank you for your help, the solution works great :)

Posted: Fri Feb 24, 2006 11:29 am
by narcis
Excellent! I'm glad to hear that fits your needs.

Posted: Thu Mar 02, 2006 9:13 am
by 9341105
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.

Posted: Fri Mar 03, 2006 9:31 am
by 9341105
Any ideas Narcis? If this is not possible we will have to implement an alternative solution without the Z axis and using the ColorGrid.

Posted: Wed Mar 08, 2006 12:01 pm
by Pep
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;

Posted: Wed Mar 08, 2006 1:05 pm
by 9341105
Using this method the ValueIndex returned is -1 when clicking in a 3D chart

Posted: Wed Mar 15, 2006 12:53 am
by Pep
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.