NullReferenceExeption while using Multiple Data Source

3 posts, 1 answers
  1. Frank
    Frank avatar
    12 posts
    Member since:
    May 2011

    Posted 01 Jun 2011 Link to this post

    Hi, 

    I'm trying to use the feature of multiple data sources in the RadChart. 
    Like this:

    XAML:
    <telerik:RadChart x:Name="Chart1">
                <telerik:RadChart.SeriesMappings>
                    <telerik:SeriesMappingCollection>
                        <telerik:SeriesMapping x:Name="Series1" ItemsSource="{Binding Data[0]}">
                            <telerik:SeriesMapping.SeriesDefinition>
                                <telerik:LineSeriesDefinition />
                            </telerik:SeriesMapping.SeriesDefinition>
                            <telerik:SeriesMapping.ItemMappings>
                                <telerik:ItemMapping FieldName="Date" DataPointMember="XValue" />
                                <telerik:ItemMapping FieldName="Value" DataPointMember="YValue" />
                            </telerik:SeriesMapping.ItemMappings>
                        </telerik:SeriesMapping>
                        <telerik:SeriesMapping x:Name="Series2" ItemsSource="{Binding Data[1]}">
                            <telerik:SeriesMapping.SeriesDefinition>
                                <telerik:LineSeriesDefinition />
                            </telerik:SeriesMapping.SeriesDefinition>
                            <telerik:SeriesMapping.ItemMappings>
                                <telerik:ItemMapping FieldName="Date" DataPointMember="XValue" />
                                <telerik:ItemMapping FieldName="Value" DataPointMember="YValue" />
                            </telerik:SeriesMapping.ItemMappings>
                        </telerik:SeriesMapping>
                    </telerik:SeriesMappingCollection>
                </telerik:RadChart.SeriesMappings>
            </telerik:RadChart>

    If the Property "Data" is loaded in the constructor of my ViewModel-Class everything works well. But as soon as the Data is loaded after setting the UserControls DataContext (Button-Command), there will raise a NullReferenceException at a point that is not comprehensible to me. 

    ViewModel:
    public class ViewModel
        {
            public ObservableCollection<ObservableCollection<ChartValueData>> Data { get; set; }
            public ICommand LoadChartCommand { get; set; }
             
            public ViewModel()
            {
                Data = new ObservableCollection<ObservableCollection<ChartValueData>>();
                LoadChartCommand = new Telerik.Windows.Controls.DelegateCommand(CreateLineChartData);
            }
     
            private void CreateLineChartData(object o)
            {
                List<ChartValueData> list = new List<ChartValueData>();
                Random random = new Random();
                for (int i = 0; i < 2; i++)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        list.Add(new ChartValueData { Date = new DateTime(2011, j + 1, 1), Value = random.Next(11, 111) });
                    }
     
                    Data.Add(new ObservableCollection<ChartValueData>(list));
                    list = new List<ChartValueData>();
                }
            }
     
        }


    Hope you could give me a hint how to get this working. 

    I created a sample project where the "bug" happens. I'd like to send you the VS-Project as a source where you can understand what my problem is. (The project is mostly the code above) 

    The same problem happens also in WPF-RadChart. We recognized that while a workmate tried to implement your chart in a WPF-Project. 

    Regards,
    Julian
  2. Answer
    Ves
    Admin
    Ves avatar
    2926 posts

    Posted 03 Jun 2011 Link to this post

    Hi Julian,

    Thanks for the details. The problem has been fixed, you can download the Latest Internal Build (currently it is from May 30-th) and give it a try.

    Kind regards,
    Ves
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Frank
    Frank avatar
    12 posts
    Member since:
    May 2011

    Posted 06 Jun 2011 Link to this post

    Thank you for the answer. The internal build works well for me.

    Regards,
    Julian
Back to Top