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

Dataseries insert causes Microsoft JScript runtime error

17 Answers 99 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 28 Jul 2011, 09:44 AM
Hi,

I am using a spline chart with 2 DataSeries on.  When the chart is drawn first time, I setup the two DataSeries objects with their DataPoints and it renders absolutely fine.

Then, at certain intervals, I check whether the source data has changed and if it has then do one of three things to the original DataSeries:

  1. If the Y value of an original datapoint has changed in the source data - adjust the value of that datapoint in the original dataseries
  2. If a value has dissappeared from the source data then the datapoint is removed
  3. If there is a new value in the source data then we either add or insert a new datapoint into the dataseries

Actions 1 and 2 are working fine.  With action 3, a call to DataSeries.Add to add to the end works fine but a call to DataSeries.Insert (to insert at a particular index) is failing with the following error:

---------------------
Microsoft JScript runtime error: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.Windows.Markup.XamlParseException:  [Line: 0 Position: 0] ---> System.NullReferenceException: Object reference not set to an instance of an object.
   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.SplineSeries.CreateFigures()
   at Telerik.Windows.Controls.Charting.SelfDrawingSeries.InitializeTopBorderLineGeometry()
   at Telerik.Windows.Controls.Charting.SelfDrawingSeries.InitializeSeriesGeometry()
   at Telerik.Windows.Controls.Charting.SelfDrawingSeries.OnApplyTemplate()
   at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)
   --- End of inner exception stack trace ---
   at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
   at MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)
   at MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)
   at System.Windows.Controls.ItemContainerGenerator.LayoutStatesManager.GetElementRoot(Boolean templatesAreGenerated)
   at System.Windows.Controls.ItemContainerGenerator.LayoutStatesManager.Load()
   at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
   at System.Windows.Controls.ItemsControl.AddVisualChild(Int32 containerIndex, DependencyObject container, Boolean needPrepareContainer)
   at System.Windows.Controls.ItemsControl.AddContainers()
   at System.Windows.Controls.ItemsControl.RecreateVisualChildren(IntPtr unmanagedObj)    
-----------------------

I noticed that when I look at the DataSeries object after my insert, for the DataPoint I inserted - the DataPoint.DataSeries member is null for that one and the next DataPoint (one of the original ones). All the others have a valid member of the parent DataSeries.

Am I misunstanding how the Insert method operates?  I'm expecting if I have 6 datapoints (indexes 0 to 5) and I insert at index 0 then the original 6 datapoints move to indexes 1 to 6 and my new datapoint goes in at index 0.  I would read the help page on this but it won't load - Click the Insert method from this page http://www.telerik.com/help/silverlight/telerik.windows.controls.charting-telerik.windows.controls.charting.dataseries_members.html

I read the post that has a similar error - http://www.telerik.com/community/forums/silverlight/chart/error-after-upgrade-to-2011-version.aspx - but I'm not reusing DataPoints or DataSeries across instances - I'm using a brand new DataPoint.

Thanks

Chris

17 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 28 Jul 2011, 10:29 AM
With regards to the help page - I realised it was going off to MSDN and it was that page that couldn't be found - located it here instead http://msdn.microsoft.com/en-us/library/ms132411.aspx

Although I'm guessing some links need to be updated.

Still, after looking at the help, I can't see what I'm doing wrong.
0
Chris
Top achievements
Rank 1
answered on 29 Jul 2011, 02:52 PM
Is anybody from Telerik able to help on this one?   :-)
0
Chris
Top achievements
Rank 1
answered on 29 Jul 2011, 04:25 PM
Hi,

A further update on this. I've found that it's not the DataSeries.Insert on it's own thats causing the issue.  It's actually a combination of a DataSeries.Insert and a DataSeries.Remove in that order.  If I change it to do the two operations the other way around then the code works fine.

Heading home for the weekend now but look forward to any feedback on this if possible.
0
Peshito
Telerik team
answered on 02 Aug 2011, 09:49 AM
Hi Chris,

Thanks for raising up the wrong links. It will be taken care of them.

Regarding your issue, I wasn't able to reproduce it. I've created a sample project following a similar scenario to yours. The project is attached to this thread so you could refer to it.

I tried adding, inserting and removing data points and they all worked fine.

In order to be able to help you further we will need more information. A runnable copy of your project would be fine.

Hope that helps.

Regards,
Peshito
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Chris
Top achievements
Rank 1
answered on 02 Aug 2011, 12:41 PM
Hi Peshito,

I slightly altered the sample code you sent over to better represent our code and have been able to reproduce the exact problem.  It seems to be always with the DataSeries.Remove line (but as outlined below in two examples, can produce slightly different errors).

In this example - just click the "First Change" button.

The new MainPage.xaml:

<UserControl x:Class="DataSeriesAddInsert.MainPage"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
  
    <Grid x:Name="LayoutRoot" Background="White" Width="750" Height="650">
        <Button Name="btnFirstChange" HorizontalAlignment="Left" VerticalAlignment="Top"
                Click="btnFirstChange_Click">First Change</Button>
        <Button Name="btnSecondChange" HorizontalAlignment="Left" Margin="0,25,0,0" VerticalAlignment="Top"
                Click="btnSecondChange_Click">Second Change</Button>
        <telerik:RadChart Name="radChart" Width="650" Height="450" />
    </Grid>
</UserControl>


The new MainPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Charting;
  
namespace DataSeriesAddInsert
{
    public partial class MainPage : UserControl
    {
        DataSeries series = new DataSeries();
        DataPoint newPoint = new DataPoint(new DateTime(2009, 5, 7).ToOADate(), 110);
  
        public MainPage()
        {
            InitializeComponent();
  
            series.Definition = new SplineSeriesDefinition();
            series.LegendLabel = "Rate Prices";
            series.Add(new DataPoint(new DateTime(2011, 7, 15).ToOADate(), 100));
            series.Add(new DataPoint(new DateTime(2011, 7, 27).ToOADate(), 110));
            series.Add(new DataPoint(new DateTime(2011, 8, 29).ToOADate(), 120));
  
            radChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
            radChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Inside;
            radChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
            radChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM";
            radChart.DefaultView.ChartArea.EnableAnimations = false;
  
            radChart.DefaultView.ChartTitle.Content = "Year 2011";
            radChart.DefaultView.ChartLegend.Header = "Legend";
            radChart.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
            //Axis X
            radChart.DefaultView.ChartArea.AxisX.Title = "Date";
  
            radChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Between;
            //Axis Y
            radChart.DefaultView.ChartArea.AxisY.Title = "Price";
  
            radChart.DefaultView.ChartArea.DataSeries.Add(series);
        }
  
  
        private void btnFirstChange_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
  
            if ((bool)button.IsPressed)
            {
                // remove A and B
                List<DataPoint> dpsToRemove = new List<DataPoint>();
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][0]);
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][1]);
  
                // HERE
  
                DataPoint point1 = new DataPoint(new DateTime(2011, 7, 18).ToOADate(), 107);
                DataPoint point2 = new DataPoint(new DateTime(2011, 7, 28).ToOADate(), 109);
  
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(0, point1);
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(1, point2);
  
                // TO TELERIK - THIS LINE WILL FAIL IN THIS EXAMPLE
                // BUT WILL WORK FINE IF MOVED TO WHERE IT SAYS "HERE" ABOVE
                dpsToRemove.ForEach(dp => radChart.DefaultView.ChartArea.DataSeries[0].Remove(dp));
            }
        }
  
        private void btnSecondChange_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            if ((bool)button.IsPressed)
            {
                // remove A and B
                List<DataPoint> dpsToRemove = new List<DataPoint>();
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][0]);
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][1]);
  
                dpsToRemove.ForEach(dp => radChart.DefaultView.ChartArea.DataSeries[0].Remove(dp));
  
                DataPoint point1 = new DataPoint(new DateTime(2011, 7, 15).ToOADate(), 100);
                DataPoint point2 = new DataPoint(new DateTime(2011, 7, 27).ToOADate(), 110);
  
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(0, point1);
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(1, point2);
            }
        }
    }
}

I also then changed this sample code again very slightly and repeated the issue in this thread - http://www.telerik.com/community/forums/silverlight/chart/need-help---nullreferenceexception-working-directly-with-the-datapoints-in-a-dataseries.aspx

In this second, example, I've moved the remove line in the codebehind for the first button so it now gets past that.  So click the "First Change" button, then the "Second Change" button and it will then fail - again on a remove line.

This involved just a quick change in the MainPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Charting;
  
namespace DataSeriesAddInsert
{
    public partial class MainPage : UserControl
    {
        DataSeries series = new DataSeries();
        DataPoint newPoint = new DataPoint(new DateTime(2009, 5, 7).ToOADate(), 110);
  
        public MainPage()
        {
            InitializeComponent();
  
            series.Definition = new SplineSeriesDefinition();
            series.LegendLabel = "Rate Prices";
            series.Add(new DataPoint(new DateTime(2011, 7, 15).ToOADate(), 100));
            series.Add(new DataPoint(new DateTime(2011, 7, 27).ToOADate(), 110));
            series.Add(new DataPoint(new DateTime(2011, 8, 29).ToOADate(), 120));
  
            radChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
            radChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Inside;
            radChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
            radChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM";
            radChart.DefaultView.ChartArea.EnableAnimations = false;
  
            radChart.DefaultView.ChartTitle.Content = "Year 2011";
            radChart.DefaultView.ChartLegend.Header = "Legend";
            radChart.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
            //Axis X
            radChart.DefaultView.ChartArea.AxisX.Title = "Date";
  
            radChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Between;
            //Axis Y
            radChart.DefaultView.ChartArea.AxisY.Title = "Price";
  
            radChart.DefaultView.ChartArea.DataSeries.Add(series);
        }
  
  
        private void btnFirstChange_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
  
            if ((bool)button.IsPressed)
            {
                // remove A and B
                List<DataPoint> dpsToRemove = new List<DataPoint>();
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][0]);
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][1]);
  
                dpsToRemove.ForEach(dp => radChart.DefaultView.ChartArea.DataSeries[0].Remove(dp));
  
                DataPoint point1 = new DataPoint(new DateTime(2011, 7, 18).ToOADate(), 107);
                DataPoint point2 = new DataPoint(new DateTime(2011, 7, 28).ToOADate(), 109);
  
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(0, point1);
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(1, point2);
            }
        }
  
        private void btnSecondChange_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            if ((bool)button.IsPressed)
            {
                // remove A and B
                List<DataPoint> dpsToRemove = new List<DataPoint>();
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][0]);
                dpsToRemove.Add(radChart.DefaultView.ChartArea.DataSeries[0][1]);
  
                // TO TELERIK - THIS LINE WILL FAIL IN THIS EXAMPLE
                dpsToRemove.ForEach(dp => radChart.DefaultView.ChartArea.DataSeries[0].Remove(dp));
  
                DataPoint point1 = new DataPoint(new DateTime(2011, 7, 15).ToOADate(), 100);
                DataPoint point2 = new DataPoint(new DateTime(2011, 7, 27).ToOADate(), 110);
  
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(0, point1);
                radChart.DefaultView.ChartArea.DataSeries[0].Insert(1, point2);
            }
        }
    }
}


I believe that these two threads are now very closely related.  I will post a message in the other thread as such to point back to this one.

The code is working against the 2011 Q2 version (2011.2.712.1040).

I look forward to hearing back from you with your findings.

Kind regards

Chris

0
Chris
Top achievements
Rank 1
answered on 02 Aug 2011, 02:26 PM
Quick note: In that very last sentence - when I said it was "working against the 2011 Q2 version..." I just meant that was the version we have and the code is compiled against not that it was 'working correctly'. 
0
Peshito
Telerik team
answered on 05 Aug 2011, 01:43 PM
Hi Chris,

We managed to reproduce your issue and seems like you have hit a bug.

Thanks for bringing this to our attention. As a result of that and the broken links you've mentioned earlier, we have updated your Telerik points.

I have forwarded the bug to our developers and ti will be fixed soon.

Meanwhile as you've already mentioned that  DataSeries.Add works fine, you could use this approach as a workaround.

Kind regards,
Peshito
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Georgi
Top achievements
Rank 1
answered on 07 Aug 2011, 08:22 AM

I face exactly the same problem. Could you please post an ID in PITS so I can track when it's fixed?

Regards,

Georgi
0
Chris
Top achievements
Rank 1
answered on 08 Aug 2011, 09:23 AM
Hi,

Peshito - thanks for confirming that it is definately a bug and not something we're doing wrong - I couldn't use the Add method all the time as we have to insert at specific positions sometimes and delete some existing datapoints.

Therefore, the only way I could resolve this was to rewrite our approach and have a DataTable instead that was then bound to the Chart using the ItemsSource member.  I then changed all the code that did the Add/Insert/Remove on the DataPoints to do Add/Insert/Remove on rows of the DataTable instead.  This obviously removed the reliance on dealing directly with DataPoints.  This has resolved our own issue but obviously Georgi and others may not be able to do the same thing.

Thanks

Chris
0
Peshito
Telerik team
answered on 10 Aug 2011, 03:22 PM
Hello Chris,

I am glad you managed to find appropriate solution for your issue.
Here is a link to the PITS where the bug ststus can be tracked.

Greetings,
Peshito
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Terence
Top achievements
Rank 1
answered on 11 Aug 2011, 01:36 AM
We are experiencing this issue as well, and for implementation reasons, can't use the DataTable/ItemsSource workaround. Anybody tracked this issue any deeper?

Cheers,
-Tim
0
Peshito
Telerik team
answered on 15 Aug 2011, 12:02 PM
Hello Terence,

You can keep tracking this issue in the PITS here.
Whenever there is a change in the bug status it will be marked there.

Regards,
Peshito
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Terence
Top achievements
Rank 1
answered on 16 Aug 2011, 07:01 PM
This is critical issue for us and the proposed workaround doesn't work for us.  If we don't have a fix we are going to have to move back to a previous release and go through another full regression cycle. What and when are the possibilities of a hot fix or at least workaround to this issue?  At the very least tell us when you are going to triage this bug that has affected multiple customers so that we and other people effected by the bug can make plans.  

Thanks
 
0
Giuseppe
Telerik team
answered on 17 Aug 2011, 08:08 AM
Hi Terence,

The fix will be included in the weekly internal build next Monday.

Sorry for the temporary inconvenience.


Best wishes,
Giuseppe
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Terence
Top achievements
Rank 1
answered on 17 Aug 2011, 10:39 PM
Giuseppe,

Thanks very much for the update.  We look forward to trying the update.

Best regards,

Terence
0
Terence
Top achievements
Rank 1
answered on 23 Aug 2011, 02:14 AM
Hi Guiseppe,

I am missing something - I don't see a new internal build.  The latest. appears to be from the 15th.  Please advise.

Thanks,

Terence


0
Terence
Top achievements
Rank 1
answered on 23 Aug 2011, 10:02 PM
We downloaded the new build this morning and started running it through regression and so far it is working great.  

Thanks,

Terence
Tags
Chart
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Peshito
Telerik team
Georgi
Top achievements
Rank 1
Terence
Top achievements
Rank 1
Giuseppe
Telerik team
Share this question
or