Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

[WPF]Graph with DateTimeAxis, show correctly indexed Data

Solved!
Go to solution

So my problem is that when i load waveform data for my graph over databinding i want to show the xaxis as zero starting timeline. I had this done in (early testing) if i remember correctly by setting

 

graph1.PreferIndexData = true;

Now in my final program i cant get it to work right. My axis looks like this:

 

axisfail.png

It makes no sense to me. I configured the DateTimeFormat like

// Remove old SampleCount axis and replace it
// with a DateTimeAxis.
AxisDateTime newAxis = new AxisDateTime();
newAxis.Orientation = Orientation.Horizontal;
newAxis.Adjuster = RangeAdjuster.None;
newAxis.MajorDivisions = new RangeLabeledDivisions { LabelPresenter = new GeneralValueFormatter("hh:mm:ss") };
newAxis.Name = "xAxis";
graph1.PreferIndexData = true;
graph1.Axes.RemoveAt(1);
graph1.Axes.Add(newAxis);

and the original measurement was like a few seconds long. At first i thought my timing data in the TDMS file was corruptet but i checked it and it seems fine.

waveformtiming.PNG

So now i hit a wall. I got no clue where i could check for errors anymore so it would be nice if someone had a good suggestion.

 

Greetings

Rizardus

0 Kudos
Message 1 of 3
(3,130 Views)
Solution
Accepted by rizardus

I believe the issue is you have configured DateTime values to display with just hours, minutes, and seconds ("hh:mm:ss") — but those values are still from a full date (just with the day, month, and year hidden), not TimeSpan values. Using PreferIndexData will disable the use of all timing information on the waveform, so the values will be plotted against “0, 1, 2, ...” index values (converted to DateTime values by the AxisDateTime).

 

To display relative time, you can use a custom value formatter (similar to the one from this question😞

 

public sealed class RelativeTimeFormatter : GeneralValueFormatter {

    public PrecisionDateTime? ZeroValue { 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 = difference.ToString(Format ?? @"hh\:mm\:ss\.ffff");
        return result;
    }
} 

 

This custom formatter assumes an AxisDouble (to provide the zero value), and assumes normal timing data (so PreferIndexData should not be set), though it could be adapted for other cases.

~ Paul H
Message 2 of 3
(3,094 Views)

Oh ok i searched the forum but somehow i didnt find that old post. It works like a charm. Thank you very much paul.

 

Greetings

rizardus

0 Kudos
Message 3 of 3
(3,088 Views)