Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Annotation to snap to an X Vs Y plot

How do I snap an Annotation to a plot that contains X-Y data?
0 Kudos
Message 1 of 22
(12,727 Views)
Hi,

It sounds like you are asking how to use XYPointAnnotations. You can set an annotation to point to a specific plot or point on a graph. Simply follow the code below.

To create a new XYPointAnnotation you can use:
XYPointAnnotation xyPoint = new XYPointAnnotation();

Then to assign the annotation to a x and y axis, you can use:
xyPoint.XAxis = xAxis1;
xyPoint.YAxis = yAxis1;

Where xAxis1 and yAxis1 are the axes on which you plan to plot the annotation. If you know the axes when you create the annotation, you could also use:

XYPointAnnotation xyPoint = new XYPointAnnotation(xAxis1, yAxis1);

Finally, to set a specific point for the annotation, you can use:
xyPoint.xPosition = 5.0;
xyPoint.yPosition = 10.3;

The properties xPosition and yPosition are doubles and can be set with variables as well. This can also be set when the annotation is created using the following:

XYPointAnnotation xyPoint = new XYPointAnnotation(xAxis1, yAxis1, 5.0, 10.3);

To see a specific code example of how to use annotations, you can go to your shipping examples and look at the CustomAnnotations example (located in your <MeasurementStudioVS2005>\DotNet\Examples\UI\WindowsForms\Graph or <MeasurementStudioVS2003>\DotNet\Examples\UI\Graph, depending on what version of Visual Studio you are using). This example specifically shows how annotations work.

Matt Mueller
National Instruments
0 Kudos
Message 2 of 22
(12,701 Views)
Does the same apply using VB6.0?
0 Kudos
Message 3 of 22
(12,697 Views)
It is quite a bit different in VB6 (I apologize, I instantly switched into .NET mode), but there is an excellent example for VB6 hosted on NI.com at Creating Annotated Cursors with the Measurement Studio Graph in Visual Basic.

The commands in the function CWGraph1_CursorChange will work the same for X vs Y Plots.

Matt Mueller
National Instruments
Message 4 of 22
(12,688 Views)
Thanks Matt,


I think that is what I was looking for!Smiley Very Happy
0 Kudos
Message 5 of 22
(12,687 Views)
Your example is fine, but can you give me an example of how to edit some of the other properties of the annotations?
0 Kudos
Message 6 of 22
(12,679 Views)
Havey,

Is there a specific property or properties you have a question about? There are quite a few annotation properties that can be edited in Visual Basic - more than we have space for here.

In the example I linked to above you can explore the properties yourself by simply adding a new line referencing the annotation and hitting the period (.) to cause the function assistance box to appear (So type "CWGraph1.Annotations(CursorIndex)." to make the function box appear in the example above). Editing an annotation's properties (and a property's properties) is as easy as following the this simple step and seeing what is suggested.

If you just have questions about using VB and Measurement Studio, you could always check out out Measurement Studio for Visual Basic Support area or you could simply search NI.com for whatever topics you need (like, Visual Basic Annotation).

Matt Mueller
National Instruments
0 Kudos
Message 7 of 22
(12,671 Views)

Hi,

I have a similar problem using the CWGraph in visual basic 6.

I'd like to snap minmaxregions to my plot. I would like the annotation to react just like a cursor. That would mean if I set the region.xcoordinates at some values they would automatically snap to the nearest plot's values.

I cannot seem to get this to work, since if I set the annotation snap mode to "pointonanyplot" or such, the region starts to neglect the shape's xcoordinates and starts using the point index as a reference.
This is also explained in the help:

If you set SnapMode to cwCSnapFloating, the shape is drawn at the values specified by CWShape.XCoordinates and CWShape.YCoordinates, and you can move the entire annotation anywhere in the graph area. If you set SnapMode to cwCSnapPointsOnPlot, the shape is centered around the plot point defined by the Plot and PointIndex properties, and you can move the shape along the plot.

Now I don't want it to center, yet I'd like to give the starting and endposition of the region and make sure it snaps too (thus I can not use cwSnapFloating). Is there a way to achieve this?

Thanks

0 Kudos
Message 8 of 22
(12,007 Views)
Hi,

Are you wanting to give a cursor a coordinate and have it attach to a point on a specific plot?  If so, take a look at this example.  It demonstrates how to create cursors and have them always attached to a point on a plot.  If this isn't what you are looking for, please let me know.

Creating Annotated Cursors
0 Kudos
Message 9 of 22
(11,991 Views)

I've seen the example before, yet I'm affraid it's not a solution for my problem.

I'll try to be more specific.

I don't have (nor specifically want) any cursors, I have a cwGraph with a plot. Now I want to highlight a part of the plot by draging the mouse horizontally on the plot. The "selection" has to snap (dynamically) to the values on the plot.
I handle this by updating a minmax region-annotation shape's xcoordinates.
This xcoordinates property of the shape have to snap to the plot-values.

I use the plot's mousedown and mousemove events to determin the initial start/end positions (Xpos) of the mouse, and I pass these values to the annotation's xcoordinates property, thus updating the highlight on the fly.

Now if the shape is "floating" the shape draws fine, yet it's not snapping to the values. If I make the shape snapping to pointsonanyplot however the shape starts acting in this "pointindex mode" (as I refer to it for now) as I wrote before, which is an unwantend different behaviour.

Is there a way to make the shape snap both it's xcoordinates to the plot instead of switching to this "pointindex-mode"?

Thanks

Message Edited by Michanovich on 04-13-2007 02:43 AM

Message Edited by Michanovich on 04-13-2007 02:43 AM

0 Kudos
Message 10 of 22
(11,987 Views)