Null Reference exception in AxisX.cs:line 384

3 posts, 0 answers
  1. Mark
    Mark avatar
    12 posts
    Member since:
    Nov 2011

    Posted 11 Nov 2011 Link to this post

    I have null reference exception with just simple code of charts components (components version 2011.2.920.35)

    System.NullReferenceException occurred
      Message=Object reference not set to an instance of an object.
      Source=Telerik.Windows.Controls.Charting
      StackTrace:
           at Telerik.Windows.Controls.Charting.AxisX.CalculateItemRange(DataSeries dataSeries, Int32 index, Boolean shouldSubtractItemWidth) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\Chart\Chart\ChartArea\Axis\AxisX.cs:line 384
      InnerException:

    Code example
          
    <telerik:RadChart Name="MonitoringChart" />
     
    private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
           MonitoringChart.SeriesMappings.Clear();
     
            var lineSeriesDefinition = new LineSeriesDefinition();
            lineSeriesDefinition.ShowItemLabels = true;
            lineSeriesDefinition.ShowItemToolTips = true;
            lineSeriesDefinition.ItemToolTipFormat = "#Y at #X{dd-MMM-yy HH:mm:ss}";
            lineSeriesDefinition.AxisName = item.Name;
     
            var items = new List<DataPoint<object>>();
            items.Add(new DataPoint<object>() { Time = DateTime.Now.AddMinutes(0), Value = 1 });
            items.Add(new DataPoint<object>() { Time = DateTime.Now.AddMinutes(1), Value = 2 });
            items.Add(new DataPoint<object>() { Time = DateTime.Now.AddMinutes(2), Value = 3 });
            items.Add(new DataPoint<object>() { Time = DateTime.Now.AddMinutes(3), Value = 4 });
     
            var seriesMapping = new SeriesMapping();
            seriesMapping.ItemsSource = items; //item.Values;
            seriesMapping.LegendLabel = item.Name;
            seriesMapping.SeriesDefinition = lineSeriesDefinition;
            seriesMapping.ItemMappings.Add(new ItemMapping() { FieldName = "Time", DataPointMember = DataPointMember.XValue });
            seriesMapping.ItemMappings.Add(new ItemMapping() { FieldName = "Value", DataPointMember = DataPointMember.YValue });
     
            MonitoringChart.SeriesMappings.Add(seriesMapping);
    }

    public class DataPoint<T>
    {
        public DataPoint()
        {
        }
     
        public DataPoint(T value, DateTime time)
        {
            Value = value;
            Time = time;
        }
     
        public T Value { get; set; }
        public DateTime Time { get; set; }
    }



  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 15 Nov 2011 Link to this post

    Hi Mark,

    We couldn't reproduce the problem with the latest binaries. You can get the latest internal build (LIB) from your account page. I have created a simple WPF application that uses your code and the latest binaries. Please test it in your environment and let us know how it is.

    All the best,
    Yavor
    the Telerik team

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. Aaron
    Aaron avatar
    14 posts
    Member since:
    Feb 2012

    Posted 29 Mar 2012 Link to this post

    I was receiving a similar Null Reference Exception due to incorrect XAML markup.  I was missing the <chart:ChartArea.DataSeries> item below.  Ensure that the RadChart XAML is structured similar to this:


    <telerikChart:RadChart>
    	<telerikChart:RadChart.DefaultView>
    		<chart:ChartDefaultView>
    			<chart:ChartDefaultView.ChartArea>
    				<chart:ChartArea>
     					<chart:ChartArea.DataSeries>
     						<chart:DataSeries>
    							<chart:DataSeries.Definition>
    								<chart:LineSeriesDefinition>
     								</chart:LineSeriesDefinition>
    							</chart:DataSeries.Definition>
     
    							<chart:DataPoint YValue="80" XValue="40909"></chart:DataPoint>
    							<chart:DataPoint YValue="85" XValue="40910"></chart:DataPoint>
    							<chart:DataPoint YValue="82" XValue="40911"></chart:DataPoint>
    							<chart:DataPoint YValue="90" XValue="40912"></chart:DataPoint>
    							<chart:DataPoint YValue="85" XValue="40913"></chart:DataPoint>
     
    						</chart:DataSeries>
     
    					</chart:ChartArea.DataSeries>
     
    				</chart:ChartArea>
    			</chart:ChartDefaultView.ChartArea>
     
    		</chart:ChartDefaultView>
    	</telerikChart:RadChart.DefaultView>
    </telerikChart:RadChart>





Back to Top