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

Null Reference exception in AxisX.cs:line 384

2 Answers 77 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 11 Nov 2011, 07:26 AM
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 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 15 Nov 2011, 09:33 AM
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 >>

0
Aaron
Top achievements
Rank 1
answered on 29 Mar 2012, 09:33 PM
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>





Tags
Chart
Asked by
Mark
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Aaron
Top achievements
Rank 1
Share this question
or