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.
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.
04-13-2016 04:58 AM
I am currently using in WPF Graph.
I created a simulation that describes the problem that I have experienced in my application (attached).
I have two threads, one generates data (in my application gets data from hardware every second), and the other copies the data to the UI (copies the data to a variable, which bind to the DataSource).
Every second I get 1000 points and adds them to the data. The first few seconds it works well, after a while it gets stuck.
I added a listbox that displays the time it takes to add the data to the variable and is increases gradually.
I have two questions:
1) Does whenever I add data, it draws all existing data again? if yes, theres a way to improve or prevent this behavior?
2) How much points the graph can represent in a single view? (what is the limitation of the graph?)
thanks,
Hodaya Shalom.
Solved! Go to Solution.
04-13-2016 11:08 AM
Looking at your example, I see you are using a WPF ObservableCollection<Point>
to hold your data. The observable collection is not very efficient and will raise an event for every individual Add
operation (very similar to the Wpf graph can't auto refresh question).
To answer your first question, the graph does draw all the data it is assigned. The simplest change to improve performance would be to switch from the general-purpose observable object collection to a data-focused collection. Changing the SignalData.Data
property in your example to ChartCollection<System.Windows.Point>
(with a large capacity), and changing the DisplayValuesThread.SetSignalData
implementation to use a single Append( data )
call, greatly improved the example's performance.
The answer to your second question greatly depends on the scenario and how the graph is configured. The graph is capable of handling many millions of samples, and in combination with the chart collection is able to process new data incrementally, also increasing performance. You may also be interested in the Optimizing the WPF Graphs help topic.
04-17-2016 03:53 AM
Actually ObservableCollection<Point> is in use just in my example, in my appliaction I use RangeObservableCollection<Point> that have a AddRange function that raise event after range added (and not per point).
I examined the ChartCollection vs the RangeObservableCollection, and the performence is similar.
I changed my example to be more like my appliaction (it's added below).
and I see that the UI stuck when I get to 1,000,000 points, although the data in cs continue to increase.
04-18-2016 01:11 PM
Debugging your updated example, I believe the issue is the Dispatcher.Invoke
calls you are using to communicate with the UI thread. Since you are using the delegate-only overload, all of the calls are sent using Normal
priority, which means that lower-priority events (like graph rendering, or data binding updates to scales) will not get processed. Using a lower priority like Render
on the four Invoke
calls un-stuck the UI in my testing.
04-20-2016 04:31 AM
When I want to display the data in running way and not every second,I divid the data to 5 and draw every 200 msec.
After some time I get delay that get bigger and the UI stuck. (project attach)
When I draw all data once I dont have a problem and it's run over the milion, and here it stuck before.
Is there a problem to draw every 200 msec?
04-20-2016 01:36 PM
I can't really offer general guidance about your example, but here are some areas I noticed that you might want to look into further:
ChartCollection<double,double>
would allow the graph to perform more optimized rendering. (I think you mentioned the example is not representative of the actual data in your application, so this may not be relevant.)