Graphing logged data


Recommended Posts

Do you want to be able to arbitrarily load any log file, or do you just want to be able to graph, say, the last week's worth of data?  If you just want to go back, say, under a few million data points then you can leverage the Persist feature of channels to extend History and store the data in an easy to access format separate from your long term data logs.  How far back in time that goes depends on your Channel Timing.  At 1 sec, you can probably go back a good couple weeks.  At 10 seconds, you can go back 6 month probably.

If you want to be able to arbitrarily load any log file, then you will have to revert to a little script.  Use File.FileOpenDialog() to ask the user what file to open, then use to open the file.  If it is CSV, you can then use File.ReadDelim() to read the entire file into an array which you can then graph.  Don't forget to close the file when done using file.close().  Something like this:

private string filename = file.fileOpenDialog()
if (isempty(filename)) // operator hit cancel
   private handle =, 1, 0, 0, 1)
   global fileData = file.readDelim(handle, -1, ",", chr(10), 0)
   system.messageBox("Error opening file: " + strLastError)

Now you have a global variable called filedata.  Assuming the csv was created with a logging set, using "DAQFactory time", you can simply plot the desired column vs the first column.  For example, the 1st data column:

X Expression:  fileData[][0]

Y Expression: fileData[][1]


Link to comment
Share on other sites

Thanks. I've set my "Persist" to 10 seconds on my channel "level" and have created a graph displaying "level" with no [0] to access all it's history. How do I scroll back in time on the graph to view this history?

Link to comment
Share on other sites

The units for Persist (and for that matter History) is points, not seconds.  These are the same thing if your Timing is 1, but if your timing is, say, 10 (seconds), then a History or Perist of 20 means that you have 200 seconds in data.

Typically the Persist will be the same size as the History or larger.  One would set the Persist the same size so that historical data persists between DAQFactory restarts.  Making the Persist bigger than the history allows you to quickly access data that would otherwise take up too much memory to have in entirely in memory.

The best way to setup the graph trace is to add [bottomAxis.currentScaleFrom, bottomAxis.currentScaleTo] after your channel, so:

myChannel[bottomAxis.currentScaleFrom, bottomAxis.currentScaleTo]

The thing about Persist is that you can only access data in Persist that is past the end of the History if you subset.  This is to prevent you from accidently pulling in the entire Persist data file.  The bottomAxis.currentScaleFrom / To variables are part of the graph and hold the current minimum and maximum values for the bottom axis scaling.  So, by subsetting using these, the graph is only asking the Persist file for data that it needs to do the graph.  Then you can just change the bottom axis scaleFrom / scaleTo to get the desired range.

Note that you can shift-click and drag a graph to pan it (if it isn't selected).  You can also drag a box, right click in the box and select zoom in or zoom out.  Both of these will "Freeze" the graph so that it doesn't move with new data.  To "Thaw" the graph, you right click in the graph and select Thaw.

There are other ways to control the graph range, it just depends on what you would like.

Link to comment
Share on other sites

OK. Seems to be working. I now have 2 graphs coming from 2 channels - "tanklevel" with no persist, "tanklevel2" with persist. Only problem is when I scroll "tanklevel2" and I'm not extremely careful with the mouse, it may scroll a little vertically also. I tried playing with the freeze options but that doesn't seem to help.

Link to comment
Share on other sites

The mouse pan isn't designed for just going left and right.  For that you should use your own transport controls, be that buttons, a scroll bar or the like.  These would either change the bottom axis scaling directly, or change global variables with the current scaling that the graph references.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.