From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Time axis on intensity graph

I have been testing the solution from M21097, using a custom axis that implements ISourceDataProvider, see attached sample code. The problem is that the timer runs fine until the underlying data structure (FixedSizeIntensityChartCollection) reaches the configured maximum capacity. At this stage the data structure removes one item when a new one is added, the result is that the timer axis freezes. Any idea how to fix this?

0 Kudos
Message 1 of 4
(2,166 Views)

The source data start returned by ISourceDataProvider should represent the first value returned by the collection assigned to the graph. When a chart collection reaches capacity, it begins discarding elements earlier in the history, so having a fixed start value will no longer match the data that the graph sees.

 

To address this, you can update the axis time whenever the chart data changes:

 

// in FixedSizeIntensityChartCollection<TZ>, add a new Start property:
public double Start => (double)_chartCollection.FirstOrDefault<Sample<ulong, TZ>>().Index / _rowCount;

// in CustomAxis, invalidate when the start time changes:
private DateTime? startTime;
public DateTime? StartTime {
    get => startTime;
    set {
        if( startTime != value ) {
            startTime = value;
            OnInvalidated( new PropertyChangedEventArgs( nameof( StartTime ) ) );
        }
    }
}

// in MainWindow.OnTimerTick, update the start time based on the current chart collection start:
...
chart.Append( y );

double chartOffset = chart.Start * Interval;
timeAxis.StartTime = baseTime.AddSeconds( chartOffset );

 

~ Paul H
0 Kudos
Message 2 of 4
(2,067 Views)

Thanks Paul. This works fine as long as the Interval equals 1. However if intervals equal two, i.e. I have 2 seconds between each datapoint, I am not sure how to configure the spacing of the axis. In old windows form intensity graph there was a default increment setting, how is this done in wpf? Do I need to create my own value formatter? Do you have an example?

0 Kudos
Message 3 of 4
(2,008 Views)

Usually, the graph gets the interval from the data source (aside: if the data source does not report an interval, then the graph would fall back to the configured default value, like the DefaultVerticalInterval set in the main window constructor of this example; but since the FixedSizeIntensityChartCollection data source does report intervals, the fallback values are not used here).

 

So to have the graph display the correct interval, we need to change the data source to report that interval. I have attached an updated version of the example that includes the interval as a new constructor parameter on the intensity chart collection (incorporated into both the data values, and the Start property).

~ Paul H
0 Kudos
Message 4 of 4
(1,987 Views)