Is there a way to create multiple charts in XAML using the DataTemplate tag and a collection of collections (e.g., ObservableCollection<Dictionary<string,int>>) as the ItemsSource? I have no need of displaying multiple series on one chart via SeriesProvider, since the keys/categorical variables in each Dictionary are not related. Below was my attempt to implement it in XAML:
01.
<
ItemsControl
Name
=
"MyCategoryCharts"
>
02.
<
ItemsControl.ItemTemplate
>
03.
<
DataTemplate
x:DataType
=
"dghelper:CategoryGroupCollection"
>
04.
<
controls:Expander
ExpandDirection
=
"Down"
05.
Header
=
"{Binding CategoryName}"
06.
FontWeight
=
"SemiBold"
>
07.
08.
<
GridView
>
09.
<
GridView.ItemTemplate
>
10.
<
DataTemplate
x:DataType
=
"Dictionary"
>
11.
<
telerikChart:RadCartesianChart
>
12.
13.
<
telerikChart:RadCartesianChart.HorizontalAxis
>
14.
<
telerikChart:LinearAxis
/>
15.
</
telerikChart:RadCartesianChart.HorizontalAxis
>
16.
<
telerikChart:RadCartesianChart.VerticalAxis
>
17.
<
telerikChart:CategoricalAxis
/>
18.
</
telerikChart:RadCartesianChart.VerticalAxis
>
19.
20.
<
telerikChart:RadCartesianChart.Grid
>
21.
<
telerikChart:CartesianChartGrid
MajorLinesVisibility
=
"X"
StripLinesVisibility
=
"X"
/>
22.
</
telerikChart:RadCartesianChart.Grid
>
23.
24.
<
telerikChart:BarSeries
ItemsSource
=
"{Binding GroupDict}"
>
25.
<
telerikChart:BarSeries.CategoryBinding
>
26.
<
telerikChart:PropertyNameDataPointBinding
PropertyName
=
"Key"
/>
27.
</
telerikChart:BarSeries.CategoryBinding
>
28.
<
telerikChart:BarSeries.ValueBinding
>
29.
<
telerikChart:PropertyNameDataPointBinding
PropertyName
=
"Value"
/>
30.
</
telerikChart:BarSeries.ValueBinding
>
31.
</
telerikChart:BarSeries
>
32.
33.
34.
</
telerikChart:RadCartesianChart
>
35.
</
DataTemplate
>
36.
</
GridView.ItemTemplate
>
37.
</
GridView
>
38.
</
controls:Expander
>
39.
</
DataTemplate
>
40.
</
ItemsControl.ItemTemplate
>
41.
</
ItemsControl
>
If there's no XAML solution for this problem, could you provide a C#/Code-behind way of creating a RadCartesianChart, i.e., a C#-equivalent of this tutorial (Getting Started with Telerik UI for UWP). I've implemented this as a workaround/alternative solution to the yet-to-be-shown XAML solution but have encountered a roadblock in assigning the CategoryBinding and ValueBinding. Below is my current progress to programmatic solution:
01.
private
RadCartesianChart CreateChart(CategoryGroupCollection coll)
02.
{
03.
// Set up chart
04.
RadCartesianChart retChart =
new
RadCartesianChart();
05.
retChart.PaletteName = PredefinedPaletteName.DefaultDark;
06.
retChart.DataContext = coll;
07.
retChart.HorizontalAxis =
new
LinearAxis();
08.
retChart.VerticalAxis =
new
CategoricalAxis();
09.
10.
// Set up the data series for the chart
11.
BarSeries series =
new
BarSeries();
12.
series.ItemsSource = coll.GroupDict;
13.
14.
// TODO: assigning CategoryBinding and ValueBinding (PropertyNameDataPointBinding)
15.
16.
// Add the series to the chart
17.
retChart.Series.Add(series);
18.
return
retChart;
19.
}
20.
21.
private
void
CreateCharts(IEnumerable<CategoryGroupCollection> dataCollection)
22.
{
23.
foreach
(CategoryGroupCollection item
in
dataCollection)
24.
{
25.
ChartsStackPanel.Children.Add(CreateChart(item));
26.
}
27.
}
28.
29.
public
class
CategoryGroupCollection
30.
{
31.
public
string
CategoryName {
get
;
set
; }
32.
public
Dictionary<
string
,
int
> GroupDict {
get
;
set
; }
33.
}