From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to move a Cursor in graphs

Hi,
I what to move a Curser in a PlotXY graph to a desired position by control of the program (not by mouse or keypads)? How does this works ?
0 Kudos
Message 1 of 7
(3,219 Views)
Look at the CVI help for the function SetGraphCursor.
Look at the graphcursors sample project that ships with CVI. It uses GetGraphCursor, not SetGraphCursor, but it gives an idea on how to work with cursors.
0 Kudos
Message 2 of 7
(3,219 Views)
yes, this is the way I expected how it should work but SetGraphCursor doesn't move the cursor!
0 Kudos
Message 3 of 7
(3,219 Views)
The CVI help for SetGraphCursor: "Sets the position of the specified graph cursor."
Try this:
Open the graphcursors sample project.
Add a command button to the UIR.
Label the button Reset Cursors and assign a callback function ResetCursor.
Add the function below to graphcursors.c
Run the project.
Move the cursors manually.
Click the Reset Cursors button.
The cursors will move.

int CVICALLBACK ResetCursor (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int localError;
switch (event)
{
case EVENT_COMMIT:
localError = SetGraphCursor (panel, PANEL_GRAPH, 1, 10, 10);
localError = SetGraphCursor (panel, PANEL_GRAPH, 3, 90, 90);

break;
}
return 0;
}
0 Kudos
Message 4 of 7
(3,219 Views)
Thank you, I thougth it shopuld be possible to move the cursor via SetGraphCursorIndex, but your solution works fine.
0 Kudos
Message 5 of 7
(3,219 Views)
You can use SetGraphCursorIndex to move the cursor also. You need to get the handle of the plot first. One easy way in a callback to get the plot handle is to use GetGraphCursorIndex. You can modify the callback from my previous comment like this. You'll see the cursor move based on the index you provide to SetGraphCursorIndex.
int CVICALLBACK ResetCursor (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int localError;
int plothandle;
int index;
switch (event)
{
case EVENT_COMMIT:
localError = SetGraphCursor (panel, PANEL_GRAPH, 1, 10, 10);
localError = SetGraphCursor (panel, PANEL_GRAPH, 3, 90, 90);
/* Figure out which plot and which point the C
ursor is over */
localError = GetGraphCursorIndex (panel, PANEL_GRAPH, 2, &plothandle, &index);
localError = SetGraphCursorIndex (panel, PANEL_GRAPH, 1, plothandle, 50);

break;
}
return 0;
}
0 Kudos
Message 6 of 7
(3,219 Views)
You need to click on Plot Data before you click on Reset Cursors or you'll get an error calling GetGraphCursorIndex or SetGraphCursorIndex: if you don't plot any data, you'll get an invalid plot handle.
0 Kudos
Message 7 of 7
(3,219 Views)