I want to use nested collections for different series types.
So that I can get lines and bars in one chart.
I have attached screenshot of what I got.
First two charts are using collection of DataPoints
Rest use collection of collections.
As you can see 1st and 3rd charts look similar except legend for 3rd chart is given from series mapping and thats fine.
But 2nd and 4th charts are different.
What I want is to be able to group nested collections.
Below is code snipped for this example.
XAML:
C#:
Actually grouping one collection is fine until I will start using milti-series charts. Where I will have both line and bar. In this situation I can figure out how to group my data.
Thanks, Alexey
So that I can get lines and bars in one chart.
I have attached screenshot of what I got.
First two charts are using collection of DataPoints
Rest use collection of collections.
As you can see 1st and 3rd charts look similar except legend for 3rd chart is given from series mapping and thats fine.
But 2nd and 4th charts are different.
What I want is to be able to group nested collections.
Below is code snipped for this example.
XAML:
<
my:RadChart
x:Name
=
"chartGrouping1"
Height
=
"150"
/>
<
my:RadChart
x:Name
=
"chartGrouping2"
Height
=
"150"
/>
<
my:RadChart
x:Name
=
"chartGrouping21"
Height
=
"150"
/>
<
my:RadChart
x:Name
=
"chartGrouping22"
Height
=
"150"
/>
C#:
private
void
Chart_Loaded(
object
sender, RoutedEventArgs e)
{
InitGroupingCharts();
InitNestedGroupingCharts();
}
private
List<DataPoint> GetGroupData()
{
List<DataPoint> groupData =
new
List<DataPoint>();
groupData.AddRange(GetAppleGroupData());
groupData.AddRange(GetBananaGroupData());
return
groupData;
}
private
List<DataPoint> GetBananaGroupData()
{
List<DataPoint> bananaGroupData =
new
List<DataPoint>();
bananaGroupData.Add(
new
DataPoint { LegendLabel =
"Banana"
, XCategory =
"Europe"
, YValue = 186 });
bananaGroupData.Add(
new
DataPoint { LegendLabel =
"Banana"
, XCategory =
"Asia"
, YValue = 187 });
bananaGroupData.Add(
new
DataPoint { LegendLabel =
"Banana"
, XCategory =
"North America"
, YValue = 132 });
return
bananaGroupData;
}
private
List<DataPoint> GetAppleGroupData()
{
List<DataPoint> appleGroupData =
new
List<DataPoint>();
appleGroupData.Add(
new
DataPoint { LegendLabel =
"Apple"
, XCategory =
"Europe"
, YValue = 145 });
appleGroupData.Add(
new
DataPoint { LegendLabel =
"Apple"
, XCategory =
"Asia"
, YValue = 164 });
appleGroupData.Add(
new
DataPoint { LegendLabel =
"Apple"
, XCategory =
"North America"
, YValue = 140 });
return
appleGroupData;
}
private
void
InitGroupingCharts()
{
List<DataPoint> groupData = GetGroupData();
SeriesMapping seriesMapping =
new
SeriesMapping();
seriesMapping.SeriesDefinition =
new
BarSeriesDefinition();
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"LegendLabel"
));
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"XCategory"
));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"YValue"
, DataPointMember.YValue, ChartAggregateFunction.Sum));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"XCategory"
, DataPointMember.XCategory));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.LegendLabel));
chartGrouping1.SeriesMappings.Clear();
chartGrouping1.SeriesMappings.Add(seriesMapping);
chartGrouping1.ItemsSource =
null
;
chartGrouping1.ItemsSource = groupData;
seriesMapping.GroupingSettings.GroupDescriptors.Clear();
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"XCategory"
));
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"LegendLabel"
));
seriesMapping.ItemMappings.Clear();
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"YValue"
, DataPointMember.YValue, ChartAggregateFunction.Sum));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.XCategory));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.LegendLabel));
chartGrouping2.SeriesMappings.Clear();
chartGrouping2.SeriesMappings.Add(seriesMapping);
chartGrouping2.ItemsSource =
null
;
chartGrouping2.ItemsSource = groupData;
}
private
void
InitNestedGroupingCharts()
{
chartGrouping21.SeriesMappings.Clear();
SeriesMapping seriesMapping =
new
SeriesMapping();
seriesMapping.CollectionIndex = 0;
seriesMapping.LegendLabel =
"A"
;
seriesMapping.SeriesDefinition =
new
BarSeriesDefinition();
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"LegendLabel"
));
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"XCategory"
));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"YValue"
, DataPointMember.YValue, ChartAggregateFunction.Sum));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"XCategory"
, DataPointMember.XCategory));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.LegendLabel));
chartGrouping21.SeriesMappings.Add(seriesMapping);
seriesMapping =
new
SeriesMapping();
seriesMapping.CollectionIndex = 1;
seriesMapping.LegendLabel =
"B"
;
seriesMapping.SeriesDefinition =
new
BarSeriesDefinition();
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"LegendLabel"
));
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"XCategory"
));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"YValue"
, DataPointMember.YValue, ChartAggregateFunction.Sum));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"XCategory"
, DataPointMember.XCategory));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.LegendLabel));
chartGrouping21.SeriesMappings.Add(seriesMapping);
chartGrouping21.ItemsSource =
null
;
List<List<DataPoint>> groupData =
new
List<List<DataPoint>>();
groupData.Add(GetAppleGroupData());
groupData.Add(GetBananaGroupData());
chartGrouping21.ItemsSource = groupData;
chartGrouping22.SeriesMappings.Clear();
SeriesMapping seriesMapping22 =
new
SeriesMapping();
seriesMapping22.CollectionIndex = 0;
seriesMapping22.LegendLabel =
"A"
;
seriesMapping22.SeriesDefinition =
new
BarSeriesDefinition();
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"XCategory"
));
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"LegendLabel"
));
seriesMapping22.ItemMappings.Add(
new
ItemMapping(
"YValue"
, DataPointMember.YValue));
seriesMapping22.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.XCategory));
seriesMapping22.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.LegendLabel));
chartGrouping22.SeriesMappings.Add(seriesMapping22);
seriesMapping22 =
new
SeriesMapping();
seriesMapping22.CollectionIndex = 1;
seriesMapping22.LegendLabel =
"B"
;
seriesMapping22.SeriesDefinition =
new
BarSeriesDefinition();
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"XCategory"
));
seriesMapping.GroupingSettings.GroupDescriptors.Add(
new
ChartGroupDescriptor(
"LegendLabel"
));
seriesMapping22.ItemMappings.Add(
new
ItemMapping(
"YValue"
, DataPointMember.YValue));
seriesMapping22.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.XCategory));
seriesMapping22.ItemMappings.Add(
new
ItemMapping(
"LegendLabel"
, DataPointMember.LegendLabel));
chartGrouping22.SeriesMappings.Add(seriesMapping22);
chartGrouping22.ItemsSource =
null
;
chartGrouping22.ItemsSource = groupData;
}
Actually grouping one collection is fine until I will start using milti-series charts. Where I will have both line and bar. In this situation I can figure out how to group my data.
Thanks, Alexey