Hi Martin.
JR is correct.
The fact that the values of plot and index are both -1 after you call
GetGraphCursorIndex() indicates that the cursor is not attached to a
plot (maybe because the control is invisible?). You need to force this
to happen after you call PlotXY().
Something like this should work (add appropriate error-checking):
...
// Plot new graphs
for (i=0; i<20; i++)
{
data[i].plothandle = PlotXY (hMainPanel, MAIN_GRAPH,
data[i].xarray, data[i].yarray,
data[i].points, VAL_DOUBLE,
VAL_DOUBLE, data[i].plotstyle,
VAL_NO_POINT, data[i].linestyle,
1, data[i].plotcolor);
}
// Forcibly attach the cursor to a plot
// (the values of n and index could be saved between callbacks if necessary)
SetGraphCursorIndex (hMainPanel, MAIN_GRAPH, 1, data[n].plothandle, index);
// If using 2 y-axes, get the y-axis for the plot...
GetPlotAttribute (hMainPanel, MAIN_GRAPH, data[n].plothandle, ATTR_PLOT_YAXIS, &yAxis);
// ... and associate the cursor with that axis
SetCursorAttribute (hMainPanel, MAIN_GRAPH, 1, ATTR_CURSOR_YAXIS, yAxis);
// Now get the cursor position and use it however you need to
GetGraphCursor (hMainPanel, MAIN_GRAPH, 1, &xPos, &yPos);
// Make Graph visible
SetCtrlAttribute (hMainPanel, MAIN_GRAPH, ATTR_VISIBLE, 1);
...
Note that your control callback is executed
before the cursor
position is updated (which happens when the control receives the
event). So, for proper operation once the user is able to interact with
the graph, you may need to do this:
...
// In the control callback
case EVENT_COMMIT:
PostDeferredCall (HandleCommitEventCB, (void *) someData);
break;
...
In HandleCommitEventCB():
...
GetGraphCursorIndex (hMainPanel, MAIN_GRAPH, 1, &plot, &index);
// etc.
...
Cheers,
Colin.