09-17-2015 09:38 AM
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.
Solved! Go to Solution.
09-17-2015 11:39 AM
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.