By default, graph cursors will be restricted to moving along one axis if you click on the cross-hairs of the cursor while holding down the shift key (you have to click within about 5 pixels of the line segment). The direction depends on which line segment you click on: if you click on the vertical line segment you move along the horizontal axis, and vice-versa. You can chose to hide either line segment, if you only want to allow movement in one direction.
But this might not be what you want, since it only enables the operator to move along one axis. It doesn't force the operator to move along the axis.
There's a possible workaround that might achieve what you want. I'm including some code here to demonstrate it. The idea is to put the cursor in snap-to-point mode, thus forcing it to always be attached to a plot. You can then draw an invisible plot on the graph that would act as a magnet for the cursor. That plot could follow the axis that you want the movement to be parallel to. In the example below, the plot will be a horizontal line drawn at y = 50.
Here's the sample code:
int i, numPoints;
double min, max, *x = NULL, *y = NULL;
GetCtrlAttribute (panelHandle, PANEL_GRAPH, ATTR_WIDTH, &numPoints);
GetAxisScalingMode (panelHandle, PANEL_GRAPH, VAL_BOTTOM_XAXIS, NULL, &min, &max);
nullChk(x = malloc (sizeof (double) * numPoints));
nullChk(y = malloc (sizeof (double) * numPoints));
for (i = 0; i < numPoints; i++)
{
x[i] = min + i * (max - min) / numPoints;
y[i] = 50.0;
}
PlotXY (panelHandle, PANEL_GRAPH, x, y, numPoints, VAL_DOUBLE, VAL_DOUBLE, VAL_SCATTER,
VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_TRANSPARENT);
A couple of notes about the code:
1. The number of points in the plot (numPoints) is somewhat arbitrary. The plot needs to be dense enough to give the user the illusion that the cursor can be placed anywhere along this line. This can be achieved by having at least as many points as there are pixels. That's why I'm basing the number of points on the width of the graph. If your axis of movement is the vertical axis, you'd want to use the height instead.
2. This code is only valid for a given min-max range of the axis. Whenever the axis changes, you'll have to delete this plot and re-plot it for the new range.
3. This is assuming linear scaling. If you use logarithimic scaling, you'll have to change the way x[i] is populated.
4. Any other plots that you have in the graph will have to have to be made "unsnappable" so that the cursor can only snap to this graph. You can do that using SetPlotAttribute (..., ATTR_SNAPPABLE, 0).
Finally, the movement of this cursor might still not be exactly what you want. When the operator clicks on the graph, the cursor will still move freely, but when the operator releases the mouse, it will snap to the plot line.
Hope this helps.
Luis
NI