ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Line tracking with multiple y axis and different amounts of data
Posted by Stephan Bielmann on Aug-05-2014 19:49
Attachments:
Hello all,

I am using the given examples found in the documentation to make line
tracking. My application uses multiple Y axes, and usually the amount
of data points is about the same on each of these axes.

There are however moments where I may for example have 3000 data
points on y axis 1, but only 4 on y axis 2. In that case it happens that
mouse tracking does only show y axis 1 values, but never one of the
y axis 2 values. Where dataSet->getPosition(xIndex) won't return a
value.

See screenshot 1 where two points do match, and screenshot 2 where
they do not.

Is Chart Director providing a simple way to avoid that problem? Or do
I need to code something by myself, in that case to make search for
a data point "near" that position with more tolerance.

Thanks for any hint,

Stephan
screenshot1.png
screenshot2.png

  Re: Line tracking with multiple y axis and different amounts of data
Posted by Peter Kwan on Aug-06-2014 00:50
Hi,

ChartDirector should show both points provided they are at the same x-coordinate.

In your second image, the x-axis label displays 139.4. I assume the blue point is at
x=139.4. But is the red point also at exactly x=139.4? If the red point is at a different x
data coordinate (such as 139.399(, it is normal that the red point is not shown, as the
track line is at 139.4.

In the "track line with data labels" sample code, there is only one vertical track line, and
it will show all data points at the track line position. The track line will be "snapped" to
the nearest data point. This ensures the track line will be at a position that always has a
data point (the nearest point). It will show more points if those points are at exactly the
same x-data coordinate as the nearest point.

As the track cursor is "programmable", of course you can change this behaviour. For
example, you can change it so show points that are "near enough" to the track line, or
the "nearest point" can be determined on a per line basis. But then you may need to
modify the display. For example, displaying the x data coordinates at the x-axis can
become confusing, because the track line in this case can show points at many different
x data coordinates.

The key workings of the track line sample code is as follows:

(a) The "double xValue = c->getNearestXValue(mouseX);" is used to "snap" the track line
to the nearest x data coordinate by considering all the data points in the chart. You can
use myLayer->getNearestXValue(....) if you want to obtain the nearest data point for the
various layers.

(b) The "layer->getXIndexOf(xValue);" obtains the data array index at that given xValue.
It will return -1 if there is no data point at the given xValue.

(c) The "dataSet->getPosition(xIndex)," obtains the y data value at the given xIndex. It
will return NoValue if the index is invalid (such as -1).

Hope this can help.

Regards
Peter Kwan

  Re: Line tracking with multiple y axis and different amounts of data
Posted by Stephan Bielmann on Aug-06-2014 15:25
Hello Peter,

thank you for pointing me into the right direction, I did not know of
layer->getNearestXValue(). I implemented the following approach
which does not take much code lines nor logic:

double xValue = c->getNearestXValue(mouseX);
int xCoor = c->getXCoor(xValue);
double nearestXLayer = layer->getNearestXValue(xCoor);
int layerXCoor = c->getXCoor(nearestXLayer);
if(layerXCoor!=xCoor && abs(xCoor-layerXCoor)<4) xValue = nearestXLayer;

Or in short, if the value of the layer is not matching the one found
on the chart, simply check if there is one within 4 pixels and take that one
instead. This is near enough, and still looks ok with a snapping track line.

Kind regards,

Stephan