03-10-2014 10:14 PM
Hi,
I need to dynamically add plot to graph.The code as follows,
ObservableCollection<Point[]> dataSource = new ObservableCollection<Point[]>();
graph.DataSource = dataSource ;
public void AddOnePlot(Point[] pointData)
{
Plot plot = new Plot();
graph.Plots.Add(plot);
dataSource.Add(pointData);
}
But when I call graph.Plots.Clear(),the error is"Range action are not supported.".How I clear all plots in graph?
Look forward to your reply.Thanks.
Solved! Go to Solution.
03-11-2014 02:37 AM
I have found a solution.
for(int i = graph.Plots.Count;i>=0;i--)
{
graph.Plots.RemoveAt(i);
}
This workaround is no problem.But for the graph.Plots.Clear() function,I don't know why it wrong.
Still hope your answer!
03-11-2014 02:40 AM
I have found a solution.
for(int i = graph.Plots.Count;i>=0;i--)
{
graph.Plots.RemoveAt(i);
}
This workaround is no problem.But for the graph.Plots.Clear() function,I don't know why it wrong.
Still hope your answer!
03-12-2014 11:12 AM
The Plots
collection on the Graph
class derives from NotifyingCollection
, which raises a single optimized aggregate event when multiple items change. The .NET ObservableCollection
on the other hand raises separate events for every modified item in the collection. The Measurement Studio controls support both models, but WPF controls like ItemsControl
do not support aggregate events (the "range actions" in the error message).
However, there is a bug in the current version of the Legend
control: if you bind the ItemsSource
property to a collection instead of to a graph, you may see this error if a default collection view gets created. To prevent this, you can serialize events (as you showed above, removing individual items instead of clearing), or you can use the NotifyCollectionChangedSimplifier
to adapt the optimized collection to the "separate event for every item" model:
xmlns:ni="http://schemas.ni.com/controls/2009/xaml/presentation"
xmlns:niPrimitives="http://schemas.ni.com/controls/2009/xaml/presentation/primitives"
...
<Grid.Resources>
<niPrimitives:NotifyCollectionChangedSimplifier x:Key="CollectionSimplifier" />
</Grid.Resources>
...
<ni:Legend ItemsSource="{Binding Plots, ElementName=graph, Converter={StaticResource CollectionSimplifier}}" />
03-12-2014 07:47 PM
Thank you.It is very helpful to me.
08-11-2015 12:59 PM
Just wanted to let you know this issue was fixed in the Measurement Studio 2015 release.