LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

move graph cursor with mouse

Hi Jason,

After further investigation into the plot area offset issue, I found that GetGraphCoordsFromPoint() requires panel coordinates and not coordinates with respect to the graph control. With this in mind, the following modified code should work:

int CVICALLBACK GraphCallback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    int xCoordinate, yCoordinate, leftButtonDown, rightButtonDown, keyModifiers;

    double xCursor, yCursor;
   
    switch (event)
    {
        case EVENT_MOUSE_MOVE:
           
            GetRelativeMouseState (panelHandle, 0,
                &xCoordinate, &yCoordinate,
                &leftButtonDown, &rightButtonDown,
                &keyModifiers);
                      
          
            if (GetGraphCoordsFromPoint (panelHandle, PANEL_GRAPH,
                    MakePoint (xCoordinate , yCoordinate),
                    &xCursor, &yCursor))
            {
                SetGraphCursor (panelHandle, PANEL_GRAPH, 1, xCursor, yCursor);
            }
        break;
    }
    return 0;
}

0 Kudos
Message 11 of 12
(960 Views)

That does put the cursor on the exact pixel position. I tried finding a simple CVI function which would find the data of the plot at that pixel x,y position.

This is how I solved it (the long way):

 

Basically I took the width of the graph. Then I got the x,y position with the extendedmouseevents. Then I used that as a percentage and used it for the index of the plot.

So if there are 100 elements (0-99 index) and the position is 10% of the graph ( mouse position x / width of graph = .10) then the index is 9. THEN I plot the cursor to index 9 of the plot and attach it there. Then I get the value of the x,y graph and show it in a text box.

 

I feel a function to convert pixel position to the axis data would be easiest and what I did does basically that. Problem solved (sorta)

 

Thanks all for ur help in letting me understand this better and settle on this option.

0 Kudos
Message 12 of 12
(945 Views)