LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading time stamp and displaying on X-axis on XY graph

Hi,
I am trying to build a XY graph. On X-axis I need to display the time stamp( thats actually number of seconds elapsed since reference time; LabVIEW format) in HH:MM:SS AM/PM(is AM?PM possible on X-axis, I doubt... plz comment) format on X-axis. How do I go about doin this? I know I need to convert that into MM, HH, SS but how do I
go about displayin it on X-axis. Displaying is my main issue. I tried all possible means to achieve this with no success!! I guess the value retrieved from file will be string. I need to convert it into number. how?(string to number function?)
Also, the values in column 1 represent timestamp in seconds, column2 - tempvalue for sensor1, column3 - tempvalue for sensor2, ans so....on....

Thanks in advance,

qhunter
0 Kudos
Message 1 of 20
(14,006 Views)
(I hope I understand correctly how your timestamp is formatted).

You can read the file as string with "read characters form file" then use "Spreadsheet string to array" with a 2D DBL as type. The first column will be your timestamp where you have to add your reference time to get the absolute time for the x-axis.

You can format the x-axis of the graph as time and also specify the desired time format. Everything is possible, even AM/PM.

Some problems with your data:
-- The time range is very big and covers many days. --> You also need to display the date.
-- Your file is not sorted by timestamp. Since processes don't typically go back in time, you should sort it before displaying (See attached example, LabVIEW 7.0).
0 Kudos
Message 2 of 20
(13,973 Views)
The solution to your problem is quite simple. First of all, If you're using the standard LV read spreadsheet from file you'll already recieve the array as numbers. If you don't, simply use the string to number conversion VIs and you're set. Now, you don't need to convert anything. When you wire the timestamp into the graph as the X axis, all you have to do is tell the graph that it's time. To do that, right click the graph, go to format and presicion, select "X axis" from the drop-down box and on the left side select "Absolute time" and that's it. The graph will now display the time, and you can change it to display whatever you want on the right. The trick is getting your data into the graph. Since you're using a number of plots you'll have to bundle the data and build an array. I've attached a VI that shows how. Since your data wasn't organized, I also copied in OpenG's code for sorting a 2D array. If your data is real, you might want to consider sorting it before saving it. As for the example, just change the file path and see how it works.

___________________
Try to take over the world!
0 Kudos
Message 3 of 20
(13,975 Views)
Sorry for stepping on your toes, Altenbach. Your answer wasn't there when I started.
Anyway, here's the attachment.

___________________
Try to take over the world!
Message 4 of 20
(13,968 Views)
Hi tst,
I couldnt find your VI. Please reattach the file.

Thanks very much for all your help and time. I really appreciate it.

Regards,

qhunter
0 Kudos
Message 5 of 20
(13,967 Views)
Hi altenbach,
Thanks so much for the time and effort. About my timestamp that was just a sample file that I generated using Excel. I am very sorry I ddint mention that. I am sorry that you wasted your efforts for sorting the array. I appreciate all your efforts.
Also, dont we need to convert the number of seconds read from file into standard time format(HH:MM:SS) I mean into corresponding min, hrs. etc? Or just specifying X-axis as absolute time solves the problem and it is taken care by itself( converting into min, hrs, etc)

Regards,

qhunter
0 Kudos
Message 6 of 20
(13,963 Views)
Just to make sure, here's the attachment again. Also, to answer your question to Altenbach - yes, once you wire a LV timestamp numerical value to a graph or chart you only have to tell LV that it's time and it will sort it out. You can also use the VIs in the Numeric>>Conversion pallette to convert the number to timestamp and the timestamp to number (just use "To DBL").

___________________
Try to take over the world!
0 Kudos
Message 7 of 20
(13,957 Views)
Hi tst n altenbach,
I was going thru the VI that you built. But I am not sure if the VI converts the timestamp correctly. I have used http://www.timeanddate.com/date/duration.html to calculate the number of seconds evolved to generate a sample data file. My time was 02 Jan 2005 5:00:00 AM. The display on the X-axis takes 20 minutes difference when I have given a difference of 1 minute(60seconds). I dont know why this is happening. Could you please explain me this.
Also, I am including my original VI in which I require the timestamp concept. How would I integrate this (timestamp VI, that you built) in my VI. Please help. My VI does the job of displaying temperature data for 'n' temperature sensors on a single XY graph with timestamp(no. of seconds elapsed since Jan 01, 1904)

Thanks in advance.


Regards,

qhunter
0 Kudos
Message 8 of 20
(13,952 Views)
Don't use the stock "read from from spreadsheet file", because it will read everything as single precision (SGL) and thus give you only 6 digits of precision. This might not be sufficient for the timestamp.

All my loops were for the purpose of sorting by timestamp. Without sorting, the code can be much simpler (see attached, LV 7.1). Just read your sample1.txt file with it. Enjoy!

(With regards to your other VI, I'll respond in a separate reply because I can only attach one file here).
0 Kudos
Message 9 of 20
(13,941 Views)
Hi Altenbach,
Thanks for your all your efforts. I am unable to figure why your VI doesn't give the right time on X-axis. It shows me a time difference of 20 minutes or sometimes 30 minutes even though my timestamps vary only by 60 seconds. I am attaching my VI for your reference. It would be ok with me to have 6 digits of precision. I am logging data every 60 seconds. So decimal point does not come into picture for my timestamp. Also, if you could modify my VI to read the timestamp from spreadsheet file, that would be really good of you. I really appreciate all your time and efforts.

Thanks in advance,

Ratnesh

FYI: The first column in my datalog file represents timestamp(number of seconds elapsed), second column: reading for temperature sensor 1, third column: reading for temperature senosr 2, and so on. I am using approx. 11 temperature sensors. I have around 11 temperature sensors to read data from
I have taken number of seconds elapsed from 03 Jan 2005 1420 hrs. This link may be useful to you.

http://www.timeanddate.com/date/duration.html
0 Kudos
Message 10 of 20
(13,919 Views)