From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

x y chart

Dear all,

 

Can anybody please explain in more detail about the reentrant xy chart buffer. vi (you can find in x y chart by NI Example Finder). I do not really understand how to use it, although I find it is very close to what I want in my program. Especially, how to set the chart lengths parameter?
0 Kudos
Message 1 of 9
(7,385 Views)

I'm not sure I understand your problem.
The VI builds an array of points which are put into a graph. It keeps the last N points in memory and displays them, along with the new data point, so it simulates the behavior of a chart. Each element (point) is a cluster of 2 elements - an X value and a Y value.

To set the chart length, simply look at the example - a number is wired into the "Chart Length (Points)" input. If that number is changed, the length of the array stored inside the VI changes accordingly. The fact that the VI is reentrant means that you can use multiple copies of it at the same time, to plot several charts. If you place probes on the wires in the example, you can see exactly what data the wires are passing.


___________________
Try to take over the world!
0 Kudos
Message 2 of 9
(7,373 Views)

Thanks tst, however, I clicked the wrong rating button for your reply.

 

It says: ‘If the locally stored chart array is not equal to the chart length, it is expanded to that length by replicating the most recently acquired point. Data in excess of the history length is discarded’.

 

What is the size of the locally stored chart array, if I use a while loop to acquire data? I am not clear in case 1, if the array is smaller, it replicates the most recently point, the displayed data is correct or not? I have thought the displayed data should be what the card is reading at the moment.

 

If the array is larger than the history length, dose it mean the most recently acquired data will be missing?

 

Therefore, Can I just set my history length to be exactly the size of the locally stored chart array?

0 Kudos
Message 3 of 9
(7,354 Views)
First, a couple of points about that VI:
1. It's written terribly, like other NI examples I've seen. In this case, we have a few things that throw us off course in regards to how the VI works, most notably the unnecessary case structure in the while loop and the auto indexing performed on the array. According to the documentation, this was done to save memory, but it's confusing.
2. The VI seems to use a variation on a popular method of data storage. If you have an uninitialized shift register in a VI, it will keep the data that's in it as long as the VI is in memory, even if it isn't open. This leads to many VIs which use this by running a loop a single iteration each time. This VI seems to do the same with a local variable, although this is the first time I see it done this way.
 
Now, the "locally stored array" is the array that's kept inside the VI, the one I just refered to in my last sentence. We don't need to worry about it. Whenever you change the size of the history length to N, the VI takes your new data point and replicates it N times and uses that as the new array. This means that you will lose all the recent graph data because you now have N points all pointing to the same coordinates. The next time the VI runs, the one at the end will be removed and replaced with a new datapoint. If you want to see this nicely, place a 100 ms wait inside the while loop in XY Chart. You will see that when you change the size, only one point remains on the graph.
 
So, to sum it up, just set the length to whatever you want. You can ignore the way the VI implements this. Now, if you want the VI not to erase your recent data points when changing history length, you will need to do some additional coding.

___________________
Try to take over the world!
Message 4 of 9
(7,340 Views)

Thanks again for your detailed explanation, although it is a bit complex to me. Therefore, I can still set whatever value for the history length according to your reply. Can I find a more elegant and straightforward x-y chart type of vi, as I just want to output my data in x y chart without data missing.

0 Kudos
Message 5 of 9
(7,331 Views)
Why don't you try using the chart?
With the chart, you simply wire the current Y value into the chart and the X value is determined by some settings (the offset, X0, and the multiplier, which is the difference in seconds between each 2 data points). You can set both of these by using property nodes for the chart. You can also set the chart to display real time by right clicking it, selecting Properties>>Format & Precision>Absolute Time.

___________________
Try to take over the world!
Message 6 of 9
(7,318 Views)

I used chart at the very beginning. However, I was not sure how to set the node properties for the chart when I was trying to output a relative time in a loop in a real time manner. Sometimes, I changed the sampling frequency when the program was running, however, time axis could not adjust accordingly and displayed the wrong time without stopping the program (in fact, I found it is the number of data acquired). Therefore, I stupidly turned to x-y chart, which I thought could be simple and straightforward by deducting the starting time outside the loop from current time within the loop.

 

I do not know whether they supply a detailed instruction about the property node for various vi.?

 

Thanks.

0 Kudos
Message 7 of 9
(7,301 Views)

The chart needs a constant frequency (the multiplier) because the points don't hold time data, just their position in the X-array and their Y value. You can change the multiplier in the middle, but you will have to recalculate the offset and it will change the time for the older points.
You can get a description for each property if you right click the property node and select Help For property name (but the description for the multiplier property is not a very good one).

This interested me a bit, so I wrote a VI to do this buffering. Note that the loop in the subVI only runs once and the uninitialized shift register which keeps the array from the last time. Also, the VI is reentrant, so you can use it for multiple charts. I wrote this VI quickly, so it may have some bugs and it could definitely stand some improvement. For example, the first time the VI is run, it could be set to fill the array with the new element.

BTW, look at the difference between this VI and the example to see what I meant when I said the example is written terribly. This VI has straight wires, things aren't cramped together, you don't have things wired into corners. I'm not sure why NI publishes examples like these, instead of taking an extra 2 minutes to clean up the diagram, but I suggest you try to keep your VIs clean. It looks better and it's easier to read.


___________________
Try to take over the world!
Message 8 of 9
(7,293 Views)

Thanks a lot! I am trying to digest your vi. And probably replace its original buffer chart with yours.

0 Kudos
Message 9 of 9
(7,280 Views)