Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF graphs: insert plot

How do I insert or move plot to be the first?

 

graph.Plots.Insert(0, _newPlot)  throws exception regarding incorrect index

 

graph.Plots.Add( _newPlot )  appends a plot, so it's the last one

 

_newPlot.Index is read-only

0 Kudos
Message 1 of 10
(7,006 Views)

Hi eugenem,

 

Can you confirm if you are using any BarPlotRenderers or AreaPlotRenderers in the plots in front of which you are inserting your new plot? I have been able to recreate this issue with those conditions and will file an appropriate report.

 

As a workaround, if you need to insert on the fly, do not use those PlotRenderers.

Jeff | LabVIEW Software Engineer
0 Kudos
Message 2 of 10
(7,000 Views)

nope, I use LineRenderer, PointRenderer, or both (as a group)

0 Kudos
Message 3 of 10
(6,994 Views)

Hmm, I am unable to recreate it with those situations.

 

Could you post some of your XAML related to the renderers? Or anything else you think is relevant to the renderers.

Jeff | LabVIEW Software Engineer
0 Kudos
Message 4 of 10
(6,984 Views)

I build them from code, but there are some details:

 

_newPlot.Renderer
{PlotRendererGroup}
[NationalInstruments.Controls.Rendering.PlotRendererGroup]: {PlotRendererGroup}
base {System.Windows.Freezable}: {PlotRendererGroup}
SupportedRenderModes: Raster | Vector


(_newPlot.Renderer as PlotRendererGroup).PlotRenderers
{PlotRendererCollection: Count=2}
[0]: {LinePlotRenderer}
[1]: {PointPlotRenderer}

 

at then I do:

graph.Plots.Insert(0, _newPlot);

 

and get exception:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

 

 

even like this it fails:

 

_newPlot = new Plot();

_newPlot.Renderer = new LinePlotRenderer() { Stroke = Brushes.White };

graph.Plots.Insert(0, _newPlot);

0 Kudos
Message 5 of 10
(6,967 Views)

Does the error message provide any additional information? Can you provide a screenshot? Since that the error is referring to the index of a collection, I would try using the plot collection instead of plot class.

Regards,

Anjelica W.
National Instruments
Product Marketing Manager
FlexLogger and TestStand
0 Kudos
Message 6 of 10
(6,932 Views)

It looks like this is an issue with how the graph handles changing renderers associated with plots.


To workaround this, I would try adding a call to graph.Refresh(); after inserting the new plot, which should force the graph to update all plots immediately.

~ Paul H
0 Kudos
Message 7 of 10
(6,920 Views)

Hi, Paul!

 

But it crashes the moment I insert plot. I won't be able to call Refresh...

 

Anyway, Plots.Add does work, but I'd like to control order of the plots as well.

0 Kudos
Message 8 of 10
(6,913 Views)

Sorry that didn’t help (as Jeff mentioned, we are having trouble reproducing your original error, so this may be due to additional state configured on the graph, like render mode or data).


From your code snippet, it looks like you are only setting the Renderer property on the new plot. If so, another workaround would be to insert the renderer into the graph’s DefaultPlotRenderers collection, rather than changing the Plots collection.


If you do need to configure other plot members, the only other workaround I can think of for the currrent Measurement Studio release would be to use Add as you suggested, and assign the renderer to graph.Plots[insertIndex] instead of to _newPlot (and update the properties of all plots after the insert index).

~ Paul H
0 Kudos
Message 9 of 10
(6,896 Views)

Just wanted to let you know this issue was fixed in the Measurement Studio 2013 release.

~ Paul H
0 Kudos
Message 10 of 10
(6,747 Views)