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;
}
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;
}