You can use a custom value formatter for the LabelPresenter
on the MajorDivisions
of your time axis. Here is a sample implementation for waveforms using precision timing, including two ways to format the time difference from Zero (mm:ss
and total seconds):
Code
public sealed class RelativeTimeFormatter : GeneralValueFormatter {
public PrecisionDateTime? ZeroValue { get; set; }
public bool DisplayMinutesAndSeconds { get; set; }
protected override string FormatCore<TData>( TData value, ValuePresenterArgs args ) {
var time = value as PrecisionDateTime?;
if( !time.HasValue )
return base.FormatCore( value, args );
// Get the first time value specified for all waveforms
// or retrieve the last start value observed by the graph.
var zeroValue = ZeroValue ?? (PrecisionDateTime)args.Data["Zero Value"];
// Determine the time from Zero.
PrecisionTimeSpan difference = time.Value - zeroValue;
// Format result.
string result;
if( DisplayMinutesAndSeconds ) {
long wholeMinutes = difference.WholeSeconds / 60;
double seconds = difference.TotalSeconds % 60;
result = wholeMinutes + ":" + seconds.ToString( "00" );
}
else {
result = base.FormatCore( difference.TotalSeconds, args );
}
return result;
}
}
XAML
<ni:AxisDouble Orientation="Horizontal">
<ni:AxisDouble.MajorDivisions>
<ni:RangeLabeledDivisions>
<ni:RangeLabeledDivisions.LabelPresenter>
<local:RelativeTimeFormatter DisplayMinutesAndSeconds="True" />
</ni:RangeLabeledDivisions.LabelPresenter>
</ni:RangeLabeledDivisions>
</ni:AxisDouble.MajorDivisions>
</ni:AxisDouble>
~ Paul H