Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

AxisPrecisionDateTime range not updating, always 01/01/0001

Hello,

 

I am trying to graph an array of AnalogWaveform<double> objects using MStudio's WPF Graph control:

 

        <ni:Graph Grid.Row="0" 
                  x:Name="_graph" 
                  RenderMode="Vector" 
                  FontFamily="Arial" 
                  Foreground="#FF7E7E7E" 
                  FontSize="12" 
                  PlotAreaBackground="#FFF9F9F9" 
                  BorderBrush="{x:Null}" 
                  BorderThickness="0"
                  DefaultInteraction="Zoom">
            <ni:Graph.Axes>
                <ni:AxisDouble Orientation="Vertical" MinorDivisions="{x:Null}">
                    ...
                </ni:AxisDouble>
                <ni:AxisPrecisionDateTime Orientation="Horizontal" RangeChanged="AxisPrecisionDateTime_RangeChanged_1">
                </ni:AxisPrecisionDateTime>
            </ni:Graph.Axes>
        </ni:Graph>

Raw data (a DependencyObject) and plots are set dynamically in code:

 

        public AnalogWaveform<double>[] RawData
        {
            get { return (AnalogWaveform<double>[])GetValue(RawDataProperty); }
            set { SetValue(RawDataProperty, value); }
        }

 

        public static readonly DependencyProperty RawDataProperty =
            DependencyProperty.Register("RawData", typeof(AnalogWaveform<double>[]), typeof(PlotView), new PropertyMetadata(new PropertyChangedCallback(OnRawDataChanged)));

        //When the RawData property changes, update the WPF Graph's Data Source.
        private static void OnRawDataChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            PlotView window = sender as PlotView;
            window._graph.DataSource = args.NewValue;
        }

 

 

 

m_dataProvider builds and returns the AnalogWaveform<double> array populated with correct PrecisionTiming information, which is then passed into the RawData property on the UI thread: 

 

                    AnalogWaveform<double>[] data = m_dataProvider.GetChannelData(selectedChannels, start, end);

                    _graph.Dispatcher.BeginInvoke(new Action(() => { RawData = data; GeneratePlots(); }));

 

Plots then get generated and added to the graph. I have checked at at this point the PrecisionDateTime information is correct (note, I tried explicitly setting the range on the graph's second axis): 

 

       private void GeneratePlots()
        {
            // Generate the plots for the legend
            Plot plot;
            List<Plot> plots = new List<Plot>();

            m_timeRange = null;

            _graph.Plots.Clear();

            foreach (AnalogWaveform<double> waveform in RawData)
            {
                if (waveform != null)
                {
                    plot = new Plot(waveform.ChannelName);
                    _graph.Plots.Add(plot);
                    plots.Add(plot);

                    if (waveform.IsPrecisionTimingInitialized && m_timeRange == null)
                    {
                        PrecisionDateTime start = waveform.PrecisionTiming.StartTime;
                        PrecisionDateTime end = start.Add(waveform.PrecisionTiming.SampleInterval.Multiply(waveform.SampleCount));

                        m_timeRange = new Range<PrecisionDateTime>(start, end);
                    }
                }
            }

            _legend.ItemsSource = plots;
            if (m_timeRange != null)
                ((AxisPrecisionDateTime)_graph.Axes[1]).Range = m_timeRange.Value;

        }

 

What I'm seeing is that the axis range is always being reset to 01/01/0001 12:00:00 AM. I added an event handler to the RangeChanged event to log whenever the range is actually changed, and this confirms that something is changing the range back to 01/01/0001 even after I explicitly change it. When I re-set the range inside this event handler to m_timeRange, the axis displays the correct range but my data is not displayed. To me, this indicates that the PrecisionTiming information is being lost somewhere behind the scenes. Does anyone know why this would happen?

 

Thanks, your help is greatly appreciated.

 

 

0 Kudos
Message 1 of 5
(6,019 Views)

By default, the PreferIndexData property is set to true for the Graph control. This means the graph uses the index values of the waveform instead of the timing information, and then coerces index values to PrecisionDateTime to match the axis (so index 0 coerces to "1 January 0001").


If you set PreferIndexData to false, the graph will use the time information and update the axis range to match that of the waveform.

~ Paul H
Message 2 of 5
(6,007 Views)

Hi Paul,

 

Thanks, that fixed the problem.

 

On a side note, where would I find documentation for things like this? I searched for at least an hour and never came across any reference to PreferIndexData.

 

 

Justin

0 Kudos
Message 3 of 5
(5,998 Views)

Unfortunately, the PreferIndexData behavior is not widely documented currently. I have create a task to update the documentation, and to look into an implementation that provides better behavior by default for your scenario of configuring the graph with a time axis.

~ Paul H
0 Kudos
Message 4 of 5
(5,994 Views)

Just wanted to let you know that PreferIndexData in the Measurement Studio 2015 release can now automatically determine the value based on your data and graph configuration.

~ Paul H
0 Kudos
Message 5 of 5
(4,507 Views)