10-14-2015 11:30 AM - edited 10-14-2015 11:31 AM
This is an issue that comes up every once in a while, most reacently here in the Idea Exchange. So I figured it was time for a nugget.
Ok, so we have data that comes in at a non-constant rate (ie, the time between samples is non-deterministic). But we want to show this data in a chart. I have heard of people creating code to build up XY graphs based on the time stamp and keep building up the arrays to do the job. But the chart can already do it all for you!
All we do here is create a waveform from our data sample and the current time. We then write that waveform directly to the chart. The display of the chart will use the value in the T0 of the waveform to know where to put the first data point in the waveform.
Attached code is in LabVIEW 2015.
10-14-2015 12:48 PM
Thank you! A picture is worth a thousand words. Running perfectly.
10-14-2015 02:21 PM
Adding to Tim's nugget...
The "NI_ChannelName" attribute of the waveform will let you set the name that appears in the plot legend.
I belive you have to right-click the chart and make sure the "ignore attributes" is NOT selected for the nugget topic and names thing to work.
If you use an array of WF's, the T0s do not have to match and the "Y"s for one or more of the WFs can be empty.
Ben
10-15-2015 02:57 AM
@Ben wrote:
Adding to Tim's nugget...
The "NI_ChannelName" attribute of the waveform will let you set the name that appears in the plot legend.
I belive you have to right-click the chart and make sure the "ignore attributes" is NOT selected for the nugget topic and names thing to work.
If you use an array of WF's, the T0s do not have to match and the "Y"s for one or more of the WFs can be empty.
Ben
Its my longterm wish that NI document all attributes that are interpreted by graphs/charts....... shameless hint to my idea ups has been declined 😞
10-15-2015 03:48 AM
Good solution, actually I use this way charts for many years. I beleive someone in the discussion forum showed me this way how to add points to a chart, maybe it was even you 🙂
10-17-2015 11:25 AM - edited 10-17-2015 11:28 AM
Very good tutorial/example!. I think I've seen this before on some forum, but I forgot about it.
However, at my work we always want relative (elapsed) time in seconds (or minutes), starting at t=0s.
Simply changing the chart properties to show relative time does not do the trick.
After some thinking, I came to the following solution which also addresses multiple channels (here 2 channels).
10-19-2015 08:03 AM
You can even plot waveforms to a chart like this. It is convenient if your plotting process is separated from the data sampling process: you might have 0 to many points in the buffer you want to plot. But beware, there are some issues related if you go that way:
Chart Redraw Issue with Multiple Plots.
10-19-2015 08:12 PM - edited 10-19-2015 08:15 PM
@donkdonk wrote:
After some thinking, I came to the following solution which also addresses multiple channels (here 2 channels).
Why so complicated? And what if you are no longer on DST or you change time zones? All you need to do is change the first time stamp into a double and be done.
10-20-2015 02:51 AM - edited 10-20-2015 03:00 AM
@crossrulz,
After posting I realized that I somehow should be able to subtract initial time. I also realized that I somehow had to deal with summertime and changing time zones. However, I did not know you can use the "convert to double" primitive. Thanks, nice solution. It does exactly what I want!
(I also realized later that I would rather put the build array primitive in the second for loop: it separates the acquired data array from the formatting to the chart).
One further remark: for educational purposes, IMO your fixed time interval is not such a good choice; now the chart shows evenly distributed points.
10-20-2015 07:32 AM
@crossrulz wrote:
@donkdonk wrote:
After some thinking, I came to the following solution which also addresses multiple channels (here 2 channels).
Why so complicated? And what if you are no longer on DST or you change time zones? All you need to do is change the first time stamp into a double and be done.
Note:
Now that you are working with Y arrays larger than a single element, dt should be taken into concideration. If the times of points already plotted conflict with the new waveforms presented to the chart, the chart will/may reset. The "will/may" qualifier ws used becuase the behaviour may have changed with LV versions.
Ben