Page 1 of 1

From XValue to data table index ?

Posted: Wed Feb 06, 2008 10:03 pm
by 9349911
Hi !

I think it is an easy task, but I can´t find a way - maybe it´s to late :roll:

I use the TColorBandTool for marking an area. I got to values back:
Tool.StartValue
Tool.EndValue

These are x values. But how du I get the resulting index of the data table? I need a call like this:

Code: Select all

Chart[0].XValue[Tool.StartValue];
I know that this wont work because XValue needs an index / integer value. How can I get the index for a given value?

Maybe I´m blinded ... :roll:

Posted: Thu Feb 07, 2008 9:29 am
by narcis
Hi Dominik,

Yes, maybe some sleeping would help :wink:.

You can use Locate method as in the code snippet I posted here.

Posted: Thu Feb 07, 2008 9:43 am
by 9349911
hi Narcis,

Ok that works ...
Chart[0].XValues.Locate(Tool.StartValue)

but one little problem left:

If you change the left position of the TColorBandTool then Tool.StartValue can contain values like 20,31252134 which is not a valid X value. The result is -1 ...

Is it possible to have a snapping for the TColorBandTool or the possibility that Locate uses the nearest value within the XValues?

Posted: Thu Feb 07, 2008 9:48 am
by narcis
Hi Dominik,

Yes, in that case you need to use TNearestTool and its GetNearestPoint method as in the examples I posted here:

http://www.teechart.net/support/viewtop ... arestpoint
http://www.teechart.net/support/viewtop ... arestpoint

An alternative would be using a TCursorTool set to Snap=true, assign the ColorBand X value to it and let the cursor snap to the nearest point.