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

NullReferenceExeption while using Multiple Data Source

2 Answers 39 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 01 Jun 2011, 03:49 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 03 Jun 2011, 09:15 AM
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
0
Frank
Top achievements
Rank 1
answered on 06 Jun 2011, 09:02 AM
Thank you for the answer. The internal build works well for me.

Regards,
Julian
Tags
Chart
Asked by
Frank
Top achievements
Rank 1
Answers by
Ves
Telerik team
Frank
Top achievements
Rank 1
Share this question
or