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: 

AnalogWaveform - memory issue over time ?

Solved!
Go to solution

I need to implement several Graphs, each with  a unique data set.

 

WPF application, data is bound in XAML to an AnalogWaveform proberty.

 

 

As far as I can see theres no possibility to clear or reset the AnalogWaveform, so it gets bigger and bigger over time, till all memory is fed up. (see the binding example from the page below)

 

http://zone.ni.com/reference/en-XX/help/372636F-01/mstudiowebhelp/html/wpfgraphplotting/#datasource

 

 

1. Why isnt there an clear option for that? How can I reset it without creating a new AnalogWaveform

 

2. Any other chance for binding data via xaml  to NI:Graph ?

Binding doesnt seem to work, only setting "graph1.DataSource" in code behind will result in a visible plot.

 

0 Kudos
Message 1 of 2
(3,908 Views)
Solution
Accepted by Treckl

The example you linked to tries to demonstrate data binding with the least amount of code possible. Using analogWaveform.Append uses the waveform's built-in change notification to notify the graph of new data. However, as you found, the just creates a larger and larger waveform, leading to memory issues.


If you want to maintain history with a fixed capacity, you can use the ChartCollectionAnalogWaveform. If you want to display individual waveforms, then you could use a more common form of WPF data binding where we use INotifyPropertyChanged to notify when a new waveform is available:


    public partial class MainWindow : Window, INotifyPropertyChanged {
        private AnalogWaveform<double> analogWaveform;

        public MainWindow( ) {
            InitializeComponent( );
            graph1.DataContext = this;
        }

        public AnalogWaveform<double> Data {
            get { return analogWaveform; }
            set {
                analogWaveform = value;
                PropertyChanged( this, new PropertyChangedEventArgs( "Data" ) );
            }
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        private void button1_Click( object sender, RoutedEventArgs e ) {
            Random random = new Random( );

            int pointCount = 100;
            double[] data = new double[pointCount];
            for( int i = 0; i < pointCount; ++i )
                data[i] = random.NextDouble( );

            Data = AnalogWaveform<double>.FromArray1D( data );
        }
    }


You could also expose Data as a dependency property in this example, which would handle the change notification automatically.

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