The main difficulty is to calculate the X position from the click position. First, you have to find the position in the graph pane. The left position of the pane is obtained by subtracting the width of the Y scale to its left position. Then there are some basic calculations to convert the click relative position to the corresponding X value, using the scale min and max.
The second point is to create a cursor. Use the "Cursor list" attribute, which is an array of all the available cursors properties, and append a new one to the list.
Attached is a simplified version of a tool I developed some times ago with the same goal.
It answers to questions you didn't ask :
- How can I move an existing cursor without creating a new one each time I click on the graph ?
answer : the cursors are only created when you hold down the key while clicking
- How can I remove a cursor ?
answer : hold the key down while clicking close to the cursor you want to delete.
Have a look at the way the closest cursor is detected, by calculating the distance between the click position and the cursors.
Since I still have difficulties with the size of the attached documents, the vi is divided in several subs.
CC
Chilly Charly (aka CC)