Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get the plotindex from the cursor?

With the CNiGraph the cursor snaps to a plot. Now I need to know where it is. I can get the name of the plot but I dont see a way to get the plotindex.
0 Kudos
Message 1 of 7
(3,267 Views)
You should be able to use CNiPlot::PointIndex to retrieve the index of the cursor on the plot it is snapped to. You can also get the X and Y positions of a cursor with the CNiPlot::XPosition and CNiPlot::YPosition properties.

Examples:
long index = myGraph.Cursors.Item(1).PointIndex;
double xpos = myGraph.Cursors.Item(1).XPosition;
double ypos = myGraph.Cursors.Item(1).YPosition;

-Tony
0 Kudos
Message 2 of 7
(3,267 Views)
Is it the plot index that you need or a reference to the plot itself? If the latter, the cursor has a Plot property that will return a reference to the plot. If you need the plot index, you could get the plot reference and loop across the graph's Plots collection to find what index the plot is at.

Out of curiosity, what are you going to use the plot index for? The main thing that I can see using it for is to index into the graph's Plots collection to get the plot, but you can already directly get that through the cursor's Plot property.

- Elton
Message 3 of 7
(3,267 Views)
I am using the plotindex to move the cursor between plots.

Please Explain: "loop across the graph's Plots collection". examples are good.

Thanks
0 Kudos
Message 4 of 7
(3,267 Views)
I mean that you could loop over the graph's plots collection and compare each plot to the cursor's plot property to find the index. Here's an example function that takes a graph and a cursor and will return the plot index of the plot that the cursor is associated with. If the plot is not found in the collection, it returns -1:

Private Function GetCursorPlotIndex(graph As CWGraph, cursor As CWCursor) As Integer

GetCursorPlotIndex = -1

If Not graph Is Nothing Then
Dim i As Integer

For i = 1 To graph.Plots.Count
Dim plot As CWPlot
Set plot = graph.Plots.Item(i)

If plot = cursor.plot Then
Get
CursorPlotIndex = i
End If

Next
End If

End Function

- Elton
0 Kudos
Message 5 of 7
(3,267 Views)
Sorry ... I forgot this was the Visual C++ forum and not the Visual Basic forum. Here's the example again in C++:

int GetCursorPlotIndex(CNiGraph& graph, CNiCursor& cursor)
{
int plotIndex = -1;
int plotCount = graph.Plots.Count;

for (int i = 1; i < plotCount; ++i)
{
CNiPlot plot = graph.Plots.Item(i);
if (cursor.Plot == plot)
{
plotIndex = i;
break;
}
}

return plotIndex;
}

- Elton
0 Kudos
Message 6 of 7
(3,267 Views)
Works Great.
Gracias..err..Thanks.
0 Kudos
Message 7 of 7
(3,267 Views)