12-20-2008 08:54 AM
Hi,
I'm new to LabVIEW (using v8.5.1) and have a question about plotting a graph on the Front Panel.
I have a vertical slider that has a basic formula applied to it. This is all within a While loop. How can I plot the output from the slider (after the formula has been applied) against time on a graph on the front panel.
A waveform graph won't let me connect it to the output from the formula (automatically shows as a broken wire), and if I use a waveform chart I just get a horizontal line with the x-axis increasing rapidly. If I move the slider this line moves up/down the y-axis. The time value on the x-axis seems to go up to 10^6 very quickly when using the waveform chart block...
Any suggestions on how I can do this so as the graph displays, say, 100 seconds of data that updates in real time as the slider is changed? I've tried locking the x-axis scale but this does nothing.
Thanks for the help 🙂
Solved! Go to Solution.
12-20-2008 11:09 AM
How often are you writing to the slider/chart? If it's in a while loop with no wait function, then you are updating many thousands a second. The chart has a default buffer size of 1024 points. After you have reached that number, old data is discarded. Also, the default delta t of the x axis is 1 so you have to change the dt setting to match the loop rate in order to accurately represent time.
How often do you really need to update the slider? In order to display 100 seconds of data, you would set the buffer size at least equal to 100 * samples/sec. So, if you had a 100 msec wait in the loop, that means 10 samples per second * 100 for a buffer size of 1000. The default setting would then be enough. Set the sample rate to 10 msec, and you need a buffer of at 10,000 points.To change the buffer size, right click on the chart and select 'Chart History Length'. To make the x axis reflect your actual sample rate, you can right click, select X Scale>Properties>Sacles and change the multiplier value. You can also do this programatically. Look at the shipping example called Real Time Chart.
p.s. It's not a good idea to have a while loop without some sort of wait. The constantly spinning loop will use a lot of windows cpu time and prevent you from effectively interacting with front panel controls.
12-20-2008 11:14 AM
I would go for the chart solution, place all the code in the while loop in an event structure with the 'Slider.Value Change' event.
That should do.
Ton
12-20-2008 11:24 AM - edited 12-20-2008 11:25 AM
A waveform graph won't let me connect it to the output from the formula (automatically shows as a broken wire),
This is normal since a waveform graph requires an array as input. Put the graph outside the loop and wire it to the formula through the loop border. Of course, the graph will not appear until the loop is stopped...
and if I use a waveform chart I just get a horizontal line with the x-axis increasing rapidly. If I move the slider this line moves up/down the y-axis.
set your waveform chart x axis to adjust automatically to the number of stored points :right-click on the graph > X scale > Autoscale X
The time value on the x-axis seems to go up to 10^6 very quickly when using the waveform chart block...
I guess you didn't insert a delay in your loop, so it's running at full speed. Insert a "wait until next ms multiple" function (from the timing sub-palette) in your while loop, and wire it to a 100 ms constant. That will give you a plotting rate of 10 points/s.
Hope this helps
Edit : Seems I'm getting too slow for these games... 😉 🙂
12-20-2008 11:36 AM
Thanks for the replies everyone! 🙂
I'll have a fiddle around with my block diagram, by the sounds of things I need to slightly adjust my While loop in order for the rest of the script (which is yet to be written!) to function properly.
12-21-2008 07:53 AM
Thanks for the suggestion Dennis - that worked perfectly 😄
12-21-2008 09:54 AM
One other quick question about waveform charts... how can I clear the data from them whenever the run button is clicked? So whenever the VI is run, the data starts plotting at time = 0, rather than time = whatever it finished at last in this session
Cheers.
12-21-2008 11:52 AM
12-22-2008 09:39 AM
altenbach wrote:
Create a property node for the chart and wire an empty array to the history data. Place it before your loop and wire the error out to the loop boundary. This ensures that it will happen before things start executing inside the loop.
Thanks for the reply. I'm a bit confused about the first bits - I've put a Property Node on the block diagram (from Programming --> Application Control), outside the while loop and connected the "Error Out" terminal to the boundary of the while loop, but don't know which array block to use and where to wire that to.
12-22-2008 11:42 AM - edited 12-22-2008 11:48 AM
Make sure you do 3 things with the property node:
1) make sure the property selected is 'History'
2) make sure the property is set to 'Write'
3) make sure the property node is outside the loop