Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Set the xycursor on a DateTime yAxis

I have a DateTime yAxis and an xycursor. I want to set the cursor to an xy position but I do not know how to do that on a DateTime axis.
0 Kudos
Message 1 of 2
(3,409 Views)
The trick is understanding how to convert a DateTime value to a double so you can assign it to the cursor's YPosition property. 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, here's how you can convert a DateTime to a double and then set the cursor to this value:

xAxis1.Range = new Range(0, 10);
yAxis1.Range = new Range(DateTime.Today, TimeSpan.FromDays(1));
yAxis1.MajorDivisions.LabelFormat = new FormatString(FormatStringMode.DateTime, "h:mm");

double xPosition = 5.0;

double yPosition = (double)DataConverter.Convert(DateTime.Now, typeof(double));

xyCursor1.MoveCursor(xPosition, yPosition);

- Elton
0 Kudos
Message 2 of 2
(3,409 Views)