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

Argument Null Exception in stacked bar in telerik conrols

1 Answer 27 Views
Chart
This is a migrated thread and some comments may be shown as answers.
kavitha
Top achievements
Rank 1
kavitha asked on 25 Mar 2014, 08:44 AM
I am creating stackedbar chart. while showing the page i am getting an error value can not be null.

Following code i have uses :


public MainPage()
{
InitializeComponent(); var rawData = new List<CustomObject>()
{

new CustomObject("A", "Grade 1", 60),
new CustomObject("A", "Grade 2", 81),
new CustomObject("B", "Grade 1", 83),
new CustomObject("B", "Grade 2", 85),
new CustomObject("C", "Grade 2", 84),


};

try
{

this.PopulateChart(rawData);
}
catch (Exception exe)
{

}
}


private void PopulateChart(List<CustomObject> rawData)
{
try
{

var groupedByCategory1 = rawData.GroupBy(co => co.Category1);

foreach (var group in groupedByCategory1)
{
foreach (CustomObject myobh in group)
{
SeriesMapping successMapping = this.CreateSeriesMapping("Category1", "Value1", myobh.Category2, myobh);
this.radChart1.SeriesMappings.Add(successMapping);

}

           public class CustomObject
          {
            public string Category1 { get; set; }
            public string Category2 { get; set; }
            public int Value1 { get; set; }
             public int Value2 { get; set; }
           
              public CustomObject(string cat1, string cat2, int val1)
                   {
                  Category1 = cat1;
                Category2 = cat2;
                Value1 = val1;
          }
        }
}
}
catch (Exception exe)
{
MessageBox.Show( exe.Message);
}
}




private SeriesMapping CreateSeriesMapping(string category, string value, string stackKey, CustomObject itemsSource)
{
SeriesMapping successMapping = new SeriesMapping() { SeriesDefinition = new StackedBar100SeriesDefinition() { StackGroupName = stackKey } };
successMapping.ItemMappings.Add(new ItemMapping(category, DataPointMember.XCategory));
successMapping.ItemMappings.Add(new ItemMapping(value, DataPointMember.YValue));
successMapping.ItemsSource = itemsSource;
return successMapping;
}




1 Answer, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 28 Mar 2014, 07:52 AM
Hi Kavitha,

The problem is that the ItemsSource of the series is expected to be an IEnumerable (or a DataSet). The CustomObject you are passing to it is neither of those and casting does not work, leaving the actual items source a null.

I do not want to make suggestions for you to change your code because of two reasons.

1. You are using the old RadChart. We have a newer control, the ChartView, which is much much faster, it is very flexible, easy to set up and more interactive. I suggest you completely remove the old RadChart along with the Charting dll which contains it. 

2. I am not sure what result you need to get. Depending on how you expect the bars to be visualized, clustered and stacked, the code will be different. If you need further assistance I will ask that you provide us with a snapshot, some drawing, of the output you need.

Again I will suggest that you do not use the old RadChart. It has many limitations that we have eliminated in the new charting solution. I hope that you will be able to migrate to the chart view.

Regards,
Petar Marchev
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Chart
Asked by
kavitha
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Share this question
or