Jump to content
Software FX Community

IndexOutOfRangeException when removing series


DaWanderer
 Share

Recommended Posts

I receive an IndexOutOfRangeException when removing a certain SeriesAttributes from the first pane of my chart (magic number seems to be between 4 and 6 before the exception is thrown).

My chart has multiple panes, and I add several series with the following code:

chart.Series.Add(series);chart.Panes[0].Series.Add(series);

and remove the same series with this code:

chart.Panes[0].Series.Remove(series);chart.Series.Remove(series);

Is this not the correct way to add and remove series from a single pane?  I've tried wrapping my Add/Remove calls in DispatcherOperationCallback methods and invoke them with the Dispatcher of the chart object, but no luck there.Here's the exception details: 

 System.IndexOutOfRangeException was unhandled  Message="Index was outside the bounds of the array."  Source="ChartFX.WPF"  StackTrace: at at.c(Int32 A_0) at b8.a(PaintMark A_0, t A_1, Double A_2, Double A_3, ao[] A_4, LogicalItemCollection A_5, LogicalItemCollection A_6) at b8.a(t A_0, Double A_1, Double A_2) at b8.f(Double A_0, Double A_1) at b8.a(Double A_0, Double A_1, Boolean A_2) at ai.OnRenderSizeChanged(SizeChangedInfo sizeInfo) at System.Windows.ContextLayoutManager.fireSizeChangedEvents() at System.Windows.ContextLayoutManager.UpdateLayout() at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at Phoenix.Windows.App.Main() in C:\MIke\Work Projects\Phoenix\Phoenix.Windows\obj\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()  InnerException:

Link to comment
Share on other sites

We will try to reproduce this error but in the meantime can you clarify the following

1) Initial state of the chart: Does it have more than one pane, which of these settings are you doing in XAML/PageLoaded/Buttons

2) Does each series has an independent ItemsSource or do they represent different properties on the Chart's ItemsSource

Regards,

JuanC

Link to comment
Share on other sites

  • 7 months later...

 I'm having a similiar problem.

 

I have a list (IList<EngineeringChartDto>) of objects (1215 of them) that I"m adding to the chart.ItemSource property.  If I sort this list by AccountDate before I set the ItemSource on the chart I get the Index outside the bounds of the array error message.

 

If I don't sort this list, it puts the items in unordered, meaning that a date time value of 1/1/2008 will show up on the right side of 6/6/2012 but does show the chart, but again, values are out of order.

 

I'm using the following code to set and transform the items and create the chart below..

chart.Series.Clear();   chart.DataTransforms.Clear();   chart.ItemsSource = null;   chart.Titles.Clear();   chart.AxisY.Title.Content = "Volumes";   CrosstabTransform dataTransform = new CrosstabTransform();   dataTransform.ValuePath = "Volume";   dataTransform.RowPath = "AccountDate";   dataTransform.ColumnPath = "ForecastYear";   chart.DataTransforms.Add(dataTransform);   chart.AxisX.Labels.BindingPath = "AccountDate";   chart.AxisX.AutoScale = true;   chart.Gallery = Gallery.Bar;   chart.AllSeries.Stacked = true;   chart.AllSeries.StackedStyle = StackedStyle.Normal;   chart.ItemsSource = items;     chart.Titles.Add(new Title("Project Volumes"));

public class EngineeringChartDto   {   private string budgetEntity;   private string commodityType;   private DateTime accountDate;   private double volume;   private int forecastYear;   public int ForecastYear   {   get { return forecastYear; }   }   public EngineeringChartDto(string budgetEntity, string commodityType, DateTime accountDate, double volume, int forecastYear)   {   this.budgetEntity = budgetEntity;   this.forecastYear = forecastYear;   this.commodityType = commodityType;   this.accountDate = accountDate;   this.volume = volume;   }     public string BudgetEntity   {   get { return budgetEntity; }   }   public string CommodityType   {   get { return commodityType; }   }   public DateTime AccountDate   {   get { return accountDate; }   }   public double Volume   {   get { return volume; }   }   }

 

 Can you help me...thanks Mike.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...