This is a migrated thread and some comments may be shown as answers.

Need help - NullReferenceException working directly with the DataPoints in a DataSeries

1 Answer 59 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 01 Aug 2011, 12:08 PM
Hi,

In the same area of code as my post here - http://www.telerik.com/community/forums/silverlight/chart/dataseries-insert-causes-microsoft-jscript-runtime-error.aspx

I'm now hitting a NullReferenceException when using the DataSeries.Remove method to remove certain DataPoint objects.

If the Spline chart is drawn with the following initial DataPoints in a DataSeries (x values are dates, y values are decimals):
  • A) 15/7/11, 100
  • B) 27/7/11, 110
  • C) 29/8/11, 120
  • D) 28/9/11, 130
  • E) 27/10/11, 140

I then directly alter the DataSeries after a certain interval (note that A, B and E get removed-  this happens in the code before any of the below Insert/Add calls)

  • A1) 18/7/11, 107  (new datapoint using DataSeries.Insert method)
  • A2) 20/7/11, 109  (new datapoint using DataSeries.Insert method)
  • C) 29/8/11, 125  (changed datapoint - just changing the y value)
  • C1) 15/9/11, 127  (new datapoint using DataSeries.Insert method)
  • D) 28/9/11, 135  (changed datapoint - just changing the y value)
  • E1) 15/11/11, 147  (new datapoint using DataSeries.Add method - as its the last one)

The spline then redraws itself.... everything is ok up to here... the DataSeries Add/Insert/Remove calls have all worked ok.

(Note: Each DataPoint has a DataItem of a custom object that has a Date property (relates to the x value), value property (relates to the y value).  When deciding whether to change existing DataPoints or insert new ones etc - its comparing the Date property of each new incoming custom object against the Date property of the DataItem of each DataPoint.)

But now, if I update the DataSeries again back with the first data - the removes are dealt with first and it should call DataSeries.Remove for DataPoints A1, A2, C1 and E1.

The code loops through the DataPoints currently in the DataSeries and checks each one against the new results thats come in from an external service (a List of the custom objects).  It then builds up a List<DataPoint> (called dpsToDelete) of the ones that need removing and then calls the following:

dpsToDelete.ForEach(r => dataSeries.Remove(r));

It fails on the first execution of the ForEach when doing the .Remove (of DataPoint A1 above) with a NullReferenceException.

But note that if I start the spline with the second set of DataPoints and just go straight back to the first set again - I don't get this error.

The stack trace for the error is:

   at Telerik.Windows.Controls.Charting.DataPoint.GetNextSignificantIndex()
   at Telerik.Windows.Controls.Charting.SplineHelper.EvaluateIndexDependencies(Int32 currentIndex, DataSeries dataSeries)
   at Telerik.Windows.Controls.Charting.SelfDrawingSeries.CalculateSplinePoints(Func`2 extractXRangeValue, Func`3 extractYRangeValue)
   at Telerik.Windows.Controls.Charting.SelfDrawingSeries.CalculateSplinePointCollections(Func`2 extractXRangeValue, Func`3 extractYRangeValue)
   at Telerik.Windows.Controls.Charting.SplineSeries.CreateFigures()
   at Telerik.Windows.Controls.Charting.SelfDrawingSeries.InitializeTopBorderLineGeometry()
   at Telerik.Windows.Controls.Charting.SelfDrawingSeries.InitializeSeriesGeometry()
   at Telerik.Windows.Controls.Charting.ChartArea.InvalidateSeriesMeasure()
   at Telerik.Windows.Controls.Charting.Axis.UpdateRangeAndStep(Double minValue, Double maxValue, Double step)
   at Telerik.Windows.Controls.Charting.Axis.UpdateRangeAndStep()
   at Telerik.Windows.Controls.Charting.Axis.BuildAxisData()
   at Telerik.Windows.Controls.Charting.AxisX.BuildAxisData()
   at Telerik.Windows.Controls.Charting.Axis.UpdateAxis()
   at Telerik.Windows.Controls.Charting.Axis.ChartAreaDataChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Telerik.Windows.Controls.Charting.ChartArea.OnDataChanged()
   at Telerik.Windows.Controls.Charting.ChartArea.UpdateChart()
   at Telerik.Windows.Controls.Charting.ChartArea.OnDataSeriesItemPropertyChanged(Object sender, PropertyChangedEventArgs e)
   at Telerik.Windows.Controls.Charting.RadHierarchicalObservableCollection`1.OnItemPropertyChanged(Object sender, PropertyChangedEventArgs args)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnPropertyChanged(PropertyChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.OnPropertyChanged(PropertyChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)
   at Telerik.Windows.Data.RadObservableCollection`1.RemoveItem(Int32 index)
   at Telerik.Windows.Controls.Charting.RadHierarchicalObservableCollection`1.RemoveItem(Int32 index)
   at Telerik.Windows.Controls.Charting.DataSeries.RemoveItem(Int32 index)
   at System.Collections.ObjectModel.Collection`1.Remove(T item)
   at Brady.Shell.Views.Shell.GraphPresentationView.<>c__DisplayClass42.<RemoveOldDataPoints>b__40(DataPoint r)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Brady.Shell.Views.Shell.GraphPresentationView.RemoveOldDataPoints(DataSeries dataSeries, DataQueryResult dataQueryResult)
   at Brady.Shell.Views.Shell.GraphPresentationView.<>c__DisplayClass12.<Update>b__9(YAxisDTO y)
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Brady.Shell.Views.Shell.GraphPresentationView.Update(DataQueryResult dataQueryResult, String graphTitle, String xAxis, List`1 yAxes, Boolean loadView)
   at Brady.Shell.Views.Shell.GraphPresentationViewModel.<UpdateView>d__9.MoveNext()
   at Caliburn.Micro.SequentialResult.ChildCompleted(Object sender, ResultCompletionEventArgs args)

Is this a known issue or am I doing something wrong?

1 Answer, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 02 Aug 2011, 12:44 PM
Hi,

I'd like to tie up this forum thread with my other similar one - http://www.telerik.com/community/forums/silverlight/chart/dataseries-insert-causes-microsoft-jscript-runtime-error.aspx

The reason is because there is now sample code in the other thread to repeat this exact problem - I took some sample code from Peshito at Telerik that he posted on that thread and altered it to reproduce both issues.

Kind regards

Chris
Tags
Chart
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Share this question
or