Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I Plot the Current Time on X-axis using Now() in VB.net

I need to plot Measurement data on the Y axis Vs. the Measurement time on the X axis of a ScatterGraph using Now to get the time in VB.net.

I tried using PlotXYAppend(Now.ToOADate,MeasData) but the TimeStamp is showing 1/1/01 10:41 for all measurements.

How can I correct this.

Thanks.
0 Kudos
Message 1 of 3
(3,596 Views)
If you want to plot DateTime values in the ScatterGraph, you will need to convert the DateTime values to doubles with the appropriate conversion factor. Your example is using ToOADate, but the Measurement Studio .NET graphs do not use OLE Automation dates for the conversion factor between DateTime and double. OA date was natural for the ActiveX controls in Measurement Studio 6.0 since they are ActiveX controls, but there is not a precedent in .NET for what the double representation of a DateTime should be other than From/ToOADate, which are really convenience methods for interop with COM interfaces.

The DateTime/double conversion factor that the Measurement Studio graphs use is a double value of 0.0 is equivalent to DateTime.MinValue and a double interval of 1.0 is equivalent to 1 second. The NationalInstruments.DataConverter class will convert from/to double and DateTime and TimeSpan with this conversion factor. For example, change your example code to this:


Dim nowValue As Date = Now()
Dim convertedValue As Double = CDbl(DataConverter.Convert(nowValue, GetType(Double)))

ScatterGraph1.PlotXYAppend(convertedValue, MeasData)


Also, you may want to look at using WaveformGraph instead of ScatterGraph. WaveformGraph and WaveformPlot plot methods have overloads for specifying DateTime and TimeSpan values for the start and increment.

- Elton
0 Kudos
Message 2 of 3
(3,588 Views)
Thanks for the help, worked like a charm.
0 Kudos
Message 3 of 3
(3,585 Views)