Trendgraph with horizontal scrollbar


Eythor

Recommended Posts

Hi

I'm looking for a way to solve following problem.

I need to open a logger file and verify data with a trendgraph with a horizontal scroll bar.

Does anyone have a explanation or an example/script how to approach ?

Best Regards

Eythor Sigurdsson

Link to comment
Share on other sites

Here is an example demonstrating it. It will require DAQFactory 5.84 (only because that is what I used).

The file, when you start it, will take data from a Test device (sin wave) and plot it in the left graph. It will also log the data using a logging set to a file called "testLog.csv", most likely in your DAQFactory installation directory. There is nothing fancy here, though I did make it so it does not log in Excel time so I didn't have to convert back to DAQFactory time on import. You should only log with Excel time checked when you actually want the data in Excel.

The right side of the screen shows a graph of loaded data. Wait a minute or so for the log file to fill up, then click the load button and select testLog.csv. It will load it, plot it, and adjust the scroll bar so you can scroll. Of course, the graph width is set to 60 seconds, so you won't get much scrolling unless you let it log for 5 minutes or so.

Here's how it works:

1) data is logged to a standard CSV file.

2) the load button has a Quick Sequence action that simply asks for the file to load, and then passes that file name to the loadData sequence. The script looks like this:

private string filename = file.FileOpenDialog("testLog.csv",,"*.csv")
if (!isempty(filename))
   ? filename
   loadData(filename)
endif

Nothing fancy here. The ? filename is optional. isempty() just checks to see if the user hit Cancel.

3) the loadData sequence looks like this:

function loadData(string filename)
   try
	  private handle = file.Open(filename, 1,0,0,1)
	  file.Read(handle) // read header and ignore
	  global datain = file.ReadDelim(handle, -1, ",", chr(10), 0)
	  dataFromFile = datain[][1]
	  dataFromFile.time = datain[][0]
	  dataFromFile = sortTime(dataFromFile)
	  loadedGraphEnd = dataFromFile.time[0]
	  Component.loadedGraphSlider.RangeMin = dataFromFile.time[numrows(dataFromFile)-1] + loadedGraphWidth
	  Component.loadedGraphSlider.RangeMax = loadedGraphEnd
	  file.Close(handle)
   catch()
	  ? strLastError
   endcatch

The file is opened for read, text mode. A single line is read so we skip over the header. Then we use the ReadDelim function to read a delimited file. This returns a two dimensional array where each column corresponds to a column in the file. The time is the first column and the data we want is the second. There is a global variable (declared in StartUp) called dataFromFile, which is what we are plotting. So, we stick the 2nd column data into dataFromFile, then stick the first column time data into the time portion of that same data. Since the log file has the newest data at the bottom, we have to call sortTime() to reverse it since DAQFactory graphs expect the newest data at the top ([0] element).

Next, we adjust the scaling of the graph and the sliders. There are two variables that control the x axis scaling: loadedGraphEnd and loadedGraphWidth. loadedGraphEnd is the time of the right side of the bottom axis, while loadedGraphWidth is the total width of the bottom axis. Its always much more convenient to use End and Width rather than Start and End (though Start and Width would work too...). When you load a file, we want to look at the most recent data, so we set loadedGraphEnd to the most recent time stamp in the file. Then we adjust the range on the scroll bar, setting the max to that same value, and the minimum to oldest timestamp plus the timeWidth (so you can't scroll off the end).

Finally the file is closed. The graph will update as soon as dataFromFile is changed.

logAndLoad.ctl

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.