05-06-2015 02:06 AM
Hi!
I have a Graph with one horizontal and two vertical axes. I want to remove the second vertical. I do:
MyGraph.Axes.RemoveAt(2);
And get:
System.ArgumentOutOfRangeException was unhandled
I checked and, the MyGraph.Axes array has indeed 3 elemets.
The Stactrace looks like this:
System.ArgumentOutOfRangeException was unhandled
HResult=-2146233086
Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source=mscorlib
ParamName=index
StackTrace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at NationalInstruments.Controls.Primitives.NotifyingCollection`1.get_Item(Int32 index)
at NationalInstruments.Controls.Internal.GraphComponentManager`2.a(Orientation A_0)
at NationalInstruments.Controls.Internal.GraphComponentManager`2.<>c__DisplayClasse.<OnScaleCollectionChanging>b__c()
at NationalInstruments.Controls.Primitives.NotifyingCollection`1.ChangeItemsCore(Int32 index, Int32 removeCount, T[] newItems)
at NationalInstruments.Controls.Primitives.AxisCollection.ChangeItemsCore(Int32 index, Int32 removeCount, ICartesianAxis[] newItems)
at NationalInstruments.Controls.Primitives.NotifyingCollection`1.ChangeItems(Int32 index, Int32 removeCount, T[] newItems)
at NationalInstruments.Controls.Primitives.NotifyingCollection`1.RemoveAt(Int32 index)
Does anybody have any ideawhat could cause this?
05-06-2015 10:12 AM
Unfortuantely, I was not able to reproduce the error. Based on your other question, I setup a graph with three plots using a ChartCollection<double> data, and three AxisDouble scales (horizontal, vertical, vertical). Could you provide more information about your setup?
05-07-2015 02:35 AM
Hi!
I made a little snippet of my program, wich reproduces the error. I Attached the cs and xaml file. I am nut sure if you need the whole project or solution, if yes, please give me a heads up, and I wil upload it. You just have to click The "turn multiaxes on" button, than the "turn multi axes off" and there is the exception!
05-07-2015 03:02 PM
I was able to reproduce the error using your code sample, and have a task to fix the issue.
It looks like the graph is only tracking axes that are explicitly referenced by plots. When you add Yaxis2 in TurnMultiAxesOn, the graph stops tracking Yaxis1. When you later remove Yaxis2 in TurnMultiAxesOff, the graph goes looking for Yaxis1, but can't find the reference and crashes.
To avoid this in the current release, you can update the plots to reference the first axis. For example, in Initgraph you could do something along the lines of:
foreach( Plot plot in SensorPanelGraph.Plots )
plot.VerticalScale = Yaxis1;
05-08-2015 02:38 AM
Thanks for the advice. But assigning all plots to the same axes defeats the point of having a multi axes graph. (Setting the axes limits individualy for each signal.)
Two peculiarities I found:
SensorPanelGraph.Axes.Add(Yaxis2); Yaxis1.BaselineStroke = Brushes.Blue; SensorPanelGraph.Plots[1].VerticalScale = Yaxis2; SensorPanelGraph.Plots[0].Renderer = MyTempRenderer1; SensorPanelGraph.Plots[1].Renderer = MyTempRenderer2; SensorPanelGraph.Axes.RemoveAt(2);
2. If I debug through the problematic part, by the time the exception comes, the Axes actually has been removed. The SensorPanelGraph.Axes has only two element.
05-08-2015 03:48 AM - edited 05-08-2015 04:17 AM
UPDATE:
I checked, if in TurnMultiAxesOn() I comment the line SensorPanelGraph.Plots[1].Verticalscale = Yaxis2; out, the exception does not occur. But the Plot does not scale to Yaxis2 either of course 😞
SensorPanelGraph.Axes.Add(Yaxis2); Yaxis1.BaselineStroke = Brushes.Blue; //SensorPanelGraph.Plots[1].VerticalScale = Yaxis2; SensorPanelGraph.Plots[0].Renderer = MyTempRenderer1; SensorPanelGraph.Plots[1].Renderer = MyTempRenderer2;
If I try to assing the Plot to Yaxis1 before removing the second axis, the same error occurs:
SensorPanelGraph.Plots[1].VerticalScale = Yaxis1; SensorPanelGraph.Axes.RemoveAt(2); Yaxis1.BaselineStroke = Brushes.Black;
05-08-2015 09:20 AM
> assigning all plots to the same axes defeats the point of having a multi axes graph
I meant only that the axis reference was needed initially. In Initgraph, the only Y axis in SensorPanelGraph is Yaxis1, so this is just making it explicit that these plots are (currently) using the default Y axis. Later on in TurnMultiAxesOn, I would expect everything to work as before when adding and assigning Yaxis2.
If you would prefer not to use this workaround, another approach would be to leave the other axes in the graph and change their Visibility to Collapsed, rather than removing them.