LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding plots programmatically to xy graph?

I'm looking for a way to add a new plot to a given xy graph at runtime, with some attributes like color of the line, linestyle etc.

My first thought in cases like this is to write a sub vi that takes a "pointer" to  the graph and the data (& attibutes) for the new plot. I'm slowly learning however that this is not the labview way to do it (can it be done like this?), so I tried to use "functional global variables" from labview basicsII course to get a sub vi where the data for all plots are kept in a shift register array. Depending on a enum input I can now "clear data", "add plot", "get data". But it is only the datapoints I can handle like this, how do I handle color and other attributes?

Maybe someone can show a good way to accomplish this?

Background: Depending on the users choices and available data a number of plots should be drawn (1-10 or so) in the same xy-graph. One typical choice for the user is to highlight one of the plots, which is then drawn brighter that the rest. The graph would include some movable cursors, and some not movable, some annotations etc.

Ola
0 Kudos
Message 1 of 10
(6,997 Views)
A single plot for an XY graph is just a cluster of two arrays: the X data and the Y data. For multiple plots you have an array of these clusters, as shown in the context help for the XY Graph:



Thus, you can simply manipulate this array to add/remove plots. Property nodes for the XY graph allow you to access a plot's properties, like color, etc.

Message Edited by smercurio_fc on 10-09-2007 12:43 PM

0 Kudos
Message 2 of 10
(6,982 Views)
Adding on to what smercurio said...
 
The property nodes are exactly what you need to use for plot and graph details.
 

Message Edited by Steve.Briggs on 10-09-2007 01:50 PM

0 Kudos
Message 3 of 10
(6,973 Views)
My problem is a program design problem more than an plot problem. Let me give an example and it may be clearer.
First I make an array with xy data (in reality:array of bundle(array-x;array-y)) and another array with color and linestyle info for each plot. Then I need a way to present these data in a xy-graph. In the main program I can build a loop around a xy-graph that cycles through the info-array, and sets the color and linestyle of each plot. But to make the code more reusable I would be nice to make a sub-vi that makes the presentation. If I move the code directly to a sub-vi the color changes etc. are made to the local xy-graph only (?) and the output from the sub's xy-graph is only the data.
 
Ola 
0 Kudos
Message 4 of 10
(6,949 Views)

Hi,

I too have had the same problem you have come across.  The only way i got this to do vaguely what i wanted was to use strict type property nodes in the subvi (not sure if that is the correct name for a strict property node either!)  and pass in control references bundled up into the subvi.  to get the strict property node i made one in the vi where the control is and cut and pasted into the subvi (The property node then became strict).  Not even sure that that is a good style of programming.  Perhaps someone else can enlighten both of us.

Regards

Craig

Message Edited by craigc on 10-10-2007 04:33 AM

LabVIEW 2012
0 Kudos
Message 5 of 10
(6,947 Views)

A comment to smercurio_fc and Steve Briggs reply on how to change the color of a certain plot in a xy-graph:

If you have more than one plot in the graph, you first need to set the correct one to active with Active plot. All further changes in color etc. change the active plot.

Ola

Message 6 of 10
(6,934 Views)
Ola_a said:

If you have more than one plot in the graph, you first need to set the correct one to active with Active plot. All further changes in color etc. change the active plot.

Yes, we're aware of this. Smiley Wink We don't always remember to tell people every little tidbit... Smiley Wink

The control reference method mentioned by Craig is a very straightforward way to do this. The reference allows the subVI to operate on the XY graph that's on the main VI. There is an example that ships with LabVIEW called "Property Nodes" that shows using a control reference to a graph which you can look at. Just open up the Example Finder and search for "references".

As for the strict business that Craig was mentioning, that refers to whether or not the reference includes datatype information. That just means you must connect a reference to a control that is of the same data type as what the subVI's reference control expects. In this case since you're just dealing with plot style it's irrelevant. An example where this would matter is if you had a VI that had a reference to a numeric control and its data type was set to be DBL, and it was specified to include data type. If you connected a reference to an I32 control you'd get a broken wire there.

0 Kudos
Message 7 of 10
(6,926 Views)
Thanks a lot smercurio_fc! 
I'll try out this control reference for modifying a xy-graph from the sub-vi.
Can I also add plots to the graf from the sub-vi using control references?
 
Ola
0 Kudos
Message 8 of 10
(6,905 Views)

Hey Ola_a,

It's good to see you are progressing with this matter...


@smercurio_fc wrote:
Yes, we're aware of this. Smiley Wink We don't always remember to tell people every little tidbit... Smiley Wink


Those little tidbit's always comeback to bite ya right in the Smiley Surprised ...well, we all know where Smiley Wink

I won't forget the little tidbit here though!  I couldn't agree more with looking at the shipped examples that NI provides.  They have a wealth of information that is given without even having to ask anyone for.  Especially when it comes to Property and Invoke Nodes, they can be a bit tricky when you first start working with them.

In regard to the datatype information, well...there's nothing more I can really say to what smercurio said other than don't mismatch your wires from the source/output to sink/input.  The representation can be changed in such a way...

 

I hope this helps in a way.  Feel free to continue asking questions. 

Message Edited by Steve.Briggs on 10-11-2007 09:01 AM

0 Kudos
Message 9 of 10
(6,891 Views)
Ola asked

Can I also add plots to the graf from the sub-vi using control references?

Yes. You can just access the "Value" property. This is the same as writing directly to a graph indicator.
0 Kudos
Message 10 of 10
(6,883 Views)