LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XY Graph Timestamp with Multiple plots

Hi.
In this project, I would like to write the data for the XY Graph from the time of the X.

And I want to display the several Plot, but when I do more than 3 items, an error occurs.

Download All
0 Kudos
Message 1 of 11
(9,368 Views)

You simply need to read the manual. They way you are using it is not even really documented.

 

You are trying to do this, while you actually need to do this (look at the yellow, upper part of the picture).

 

(of course there are many other ways to arrange the data (complex, etc.)

 

(You also should not autoindex on a while loop. Doen't the graph belong inside the loop so you see the data as it is acquired? Sonce your points are spaced equally in time, all you need is a plain graph. Even a chart might be sufficient. Keep it simple!)

Message 2 of 11
(9,357 Views)

If you look at the Help for your XY Graph (type Ctrl-H to turn on Help, then hover over the Graph on the Block Diagram), you'll see that each Plot on the Graph is a cluster of two Arrays, the X values and the Y values, and to make multi-plot Graphs, you combine single plot Graphs into an array.

 

Sometimes it helps to write a simple all-numeric example using random numbers (so you don't have to fiddle with controls).  I'll walk you through this one ...

TimeDate Plots.png

So 10 times a second points are generated.  Rather than have my X coordinate be a Date/Time value, I chose to display "Elapsed seconds", which I get by taking the difference between the TimeStamp of point generation (inside the loop) and the TimeStamp when the program started (outside the loop).  I'll use the X array for all of my plots, so I just bring it out as an array of X values.

 

For my Y, I want N=3 plots, all Random Numbers, but offset by the index I, so Plot 0 will be [0,1], Plot 1 will be 1 + [0,1] = [1, 2], and Plot 2 will be [2, 3].  My inner For loop makes an Array of "single points for multiple plots", and when I bring it out through an indexed tunnel, I have a 2D array of M "triples" of points.  Well, I need a 2D array of 3 sets of M Values, which I get from the Array Transpose function.

 

I'm now ready to assemble my 3 plots.  In a For Loop, I bring the (constant) X Array in through a non-indexing Tunnel (since I want the entire Array, not each element) and bring the Y 2D Array in through an Indexing Tunnel (which gives me, one at a time, each of my three Y Arrays).  I combine these in a Cluster (remember, a Plot is a Cluster of X and Y array values), then let the For loop build my Array of Plots.  Wire that to the Graph, and run the program.

 

Bob Schor

0 Kudos
Message 3 of 11
(9,345 Views)

Hi Bob. I get your point and I successfully build that Vı but I have problem with writing the datas simultaneously. In that solution, at the end we get all datas but I want to get all datas one by one by the time. Do you have solution for that? Bec. I couldnt solve it and I tried many cases!

0 Kudos
Message 4 of 11
(8,506 Views)

At first, I didn't understand your question (it's really my fault, I wasn't thinking clearly), but when I ran my code snippet and saw the plots, I immediately realized what you meant.

 

You do not want a Graph -- you want a Chart!  Using a Chart (which plots data as they evolve) is very simple.  I'm going to leave (as an "exercise for the reader") the problem of how to get the Time axis to show in units of tenths of a second ...

Chart Example.png

Here's an Assignment for you -- learn about LabVIEW Charts.  You might start in LabVIEW Help -- click the Contents tab, go to Fundamentals, then go to Graphs and Charts.

 

Bob Schor

0 Kudos
Message 5 of 11
(8,499 Views)

snippet.png

Here is my snippet. I know it but I could not do it. The graph gives me only one of them. But I want 3 of them. This is different solution. But in your solution I want to tick count as well.

0 Kudos
Message 6 of 11
(8,495 Views)

 large.png

Here I can not wire cluster to array with output of the for loop. By the way, thanks a lot for replying 🙂

0 Kudos
Message 7 of 11
(8,489 Views)

OK, now I'm totally confused.  I thought (in my first response) I knew what you wanted to do, changed my mind and in my second response, thought I knew what you wanted to do, but now, I gather that I really do not know what you want to do.

 

Without resorting to any LabVIEW code, can you simply say, in words, what you want to do?  How many channels of data are you examining?  [I think the answer is "3"].  How fast are the data being generated?  [I think the answer is "at 10 Hz, i.e. every 100 msec"].  Finally, and most important, what do you want to do with these data points?

  • My first thought was that you wanted to collect them for some period, then when the period was over, plot them on a single graph as three lines (possibly overlapping).  Another possibility is that you would construct three plots and plot each channel on a different graph.
  • My second thought is that you wanted to plot the data as they were evolving (on either a single chart having three channels, or possibly on three separate charts).
  • Both thoughts seem to not be what you want.  Somehow, you also want to get the elapsed time in the plot.  Do you not realize that if you sample something at equally spaced (time) intervals, that time is implicit in the X axis?  Is the problem that you don't understand how to make the X axis show the proper time units (i.e. if the plot shows 100 data points taken at 10 Hz, getting the axis to show 0, 1, 2, ... 9 instead of 0, 1, 2, ... 99)?  That was the point of my suggesting you learn about Charts by reading the LabVIEW Help, which will explain how you can rescale the X axis.
  • Once I (and other readers of this Forum) understand better what you want to do, we can show you how to do it!  Don't give up!
  • I have a (probably-well-deserved) reputation on this Forum for saying "No Pictures!".  However, if you can generate a diagram (an Excel Graph, for example) that illustrates the "What I want to do" better than 1000 words, go ahead and attach it!
  • [Explanation -- there's a saying, "A Picture is worth a thousand words"].

Bob Schor

 

0 Kudos
Message 8 of 11
(8,477 Views)

I really sorry about that Bob! I did not hear your reputation,that was my fault. I confused you.

I wanted to plot the data as they were evolving on a single chart having three channels at 10 Hz, i.e. every 100 msec.Then I want to transfer and collect them(randomly generated numbers) at an Excel file.(Actually, later times,I will shift 3 random number generator with some program which collects datas from outside(experiment) to the charts with evolving time but for now, I try basics and put random num. generator) My X axis will be a elapsed time from 0 up to 1 sec. or any second that I put there.I  understand how to make the X axis show the proper time units but I can not combine the time stamp with my datas in a single chart as they were evolving. I hope I could express my problem truly. Thanks for replying!

0 Kudos
Message 9 of 11
(8,469 Views)

OK.  My example generating the Chart gives you the X, Y, Z numbers that you can put into a Delimited Spreadsheet (or, alternatively, you can write, using the Report Generation Toolkit, as an Excel .xlsx Worksheet).

 

For the sake of argument, let's not worry if you are writing a .csv (Delimited Spreadsheet) or .xlsx (RGT, Excel) file.  I'm going to choose to write each sample, i.e. X, Y, and Z, as a row.  So if I take two samples having values 1, 2, 3 and 4, 5, 6, my file will look like:

 1, 2, 3

 4, 5, 6  (comma-separated format).

If I wanted to be "extra fancy", I could put a first row with "  X, Y, Z".

 

I think you said that the plotting of these values in a chart was fine, what you were "missing" was an (initial) "t" column having the time values.  But these are almost trivially generated -- 0, 0.1, 0.2, 0.3 etc.  So your final .csv output would look like:

     t, X, Y, Z

 0.0, 1, 2, 3

 0.1, 4, 5, 6

 

Note that my "t" column is elapsed time, not a TimeStamp.  I'm sure you understand how to compute Elapsed Time -- it is just the index of the While/For loop ("i") times the loop period (0.1 sec).  What if you want a TimeStamp?  That's equally simple -- you need to get the Time when you enter the loop (I'll call this "t0"), then simply add (and save) t0 + t (where t is the elapsed time in seconds).  Play around with the time functions a little so that you understand how they work.

 

So, to summarize -- When you sample data at a fixed rate, you get (3) data values + an implicit time value (the index of the loop).  For plotting purposes, time becomes the X value of the plot, and the data become the (3) Y values.  If you want to save the data in a Spreadsheet (.csv or .xlsx), you simply generate the (implicit, for a chart) Time value and combine it with the data values to create a row of the output file.

 

I hope this is clear.  You have all the data present, you just need to compute the Time (either as Elapsed Time or Time(s) of occurance) from the Loop Index * Loop Period and prepend it to the Data Values to form the row of Time + Data Values.

 

Bob Schor

 

0 Kudos
Message 10 of 11
(8,454 Views)