Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Graph - exception in NationalInstruments.Controls.Graphs.dll

Solved!
Go to solution

Hello.

I am using NI Graphs in my WPF application. The graphs are binded to ChartCollection<TimeSpan, double> object. See following graph:

 

2018-01-04_14h09_51.png

 

The graph has a lot of plots, so I had to increase capacity of ChartCollection. But when I increase capacity of ChartCollection object for example to 100.000.000, ni:Graph generate following exception when binding data, and application crash down.

 

A first chance exception of type 'System.OutOfMemoryException' occurred in NationalInstruments.Controls.Graphs.dll
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at NationalInstruments.Controls.Internal.ChartDataStore`1.UpdateCapacity(Int32 newCapacity)
   at NationalInstruments.Controls.ChartCollection`2.set_Capacity(Int32 value)
   at DeratingEvaluation.Test.LoadFiles(String path) in ...

 

What is the maximum of the capacity I can use? The ChartCollection object capacity is limited by Int32, i.e. up to 2.147.483.647.

Unfortunately I need to show many plots with many points so I need to increase the capacity so much.

 

Thank you for help.

 

0 Kudos
Message 1 of 3
(3,086 Views)
Solution
Accepted by topic author Zelva

The graph has a lot of plots, so I had to increase capacity of ChartCollection.


(Just to be clear, a chart collection contains data for just one plot. Increasing the capacity of an individual chart collection will not increase the number of plots in the graph; it will only increase the number of samples for a particular plot. You do mention “show many plots with many points” later on, so your usage sounds correct, but I wanted to make sure we started on the same page.)

 


...when I increase capacity of ChartCollection<TimeSpan, double> object for example to 100.000.000, ni:Graph generate following exception when binding data, and application crash down.

 

A first chance exception of type 'System.OutOfMemoryException' occurred in NationalInstruments.Controls.Graphs.dll
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at NationalInstruments.Controls.Internal.ChartDataStore`1.UpdateCapacity(Int32 newCapacity)
   at NationalInstruments.Controls.ChartCollection`2.set_Capacity(Int32 value)
   at DeratingEvaluation.Test.LoadFiles(String path) in ...

(Again just to clarify: the exception happens in the chart collection itself, before it reaches the graph.)

 

The chart collection works by immediately allocating the specified capacity, and then recording values into that pre-allocated storage as they are appended. So when you set the capacity to 100 000 000, internally the chart will allocate TimeSpan and double arrays for that many samples. Since both TimeSpan and double take 8 bytes, the chart collection is allocating 2 × 8 × 100 000 000 ≈ 1.5 GiB of memory for one of your plots.

 



What is the maximum of the capacity I can use?

Theoretically, the maximum assignable capacity will vary based on the type of data in the chart collection and the amount of memory available on the machine. Practically speaking though, the capacity is intended to represent the maximum amount of history you want to preserve for a plot in your application.

 

The chart collection assumes that you only care about a fixed window of history, and will discard old values as new ones are appended. If your application has a different model (i.e. accumulating history without a pre-defined limit), then a different usage model or a different data type may be more appropriate (for example, gradually updating capacity as you append more data; or using the Append method on an analog waveform; or possibly a custom data type matching your specific needs).

 

To give a better answer, it would be helpful to know the desired behavior your application is trying to get from the graph and the data assigned to it.

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

Thank you very much for detailed explanation. Actually I have a collection of chart collections, so I have more plots in one graph (for example 60 plots in one graph, each plot will have about 100.000 points, values are double = 8 bytes). And I need dynamic accumulating of history without pre-defined limit so I have solved it, as you suggested, by gradually updating capacity as appending data. This works well. Thank you for tips.

 

 

0 Kudos
Message 3 of 3
(3,056 Views)