Is it possible to use a ChartSeriesProvider with a CompositeCollection as the Source? Just specifying one as a StaticResource (which works fine for something like a ListBox that uses ItemsSource) results in an exception:
Could not find property 'SeriesType' for type 'System.Windows.Data.CollectionContainer'
Example source of what I'm trying to do (modified version of the example Petar provided in this thread:
And the ViewModel:
Could not find property 'SeriesType' for type 'System.Windows.Data.CollectionContainer'
Example source of what I'm trying to do (modified version of the example Petar provided in this thread:
<
Window
x:Class
=
"TwoDynamic.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Window.Resources
>
<
CollectionViewSource
x:Key
=
"FirstList"
Source
=
"{Binding Path=Series1}"
/>
<
CollectionViewSource
x:Key
=
"SecondList"
Source
=
"{Binding Path=Series2}"
/>
<
CompositeCollection
x:Key
=
"NewList"
>
<
CollectionContainer
Collection
=
"{Binding Source={StaticResource FirstList}}"
/>
<
CollectionContainer
Collection
=
"{Binding Source={StaticResource SecondList}}"
/>
</
CompositeCollection
>
</
Window.Resources
>
<
Grid
>
<
telerik:RadCartesianChart
>
<
telerik:RadCartesianChart.Resources
>
<
Style
TargetType
=
"telerik:LineSeries"
>
<
Setter
Property
=
"StrokeThickness"
Value
=
"2"
/>
<
Setter
Property
=
"Stroke"
Value
=
"Blue"
/>
</
Style
>
<
Style
TargetType
=
"telerik:BarSeries"
>
<
Setter
Property
=
"CombineMode"
Value
=
"None"
/>
</
Style
>
</
telerik:RadCartesianChart.Resources
>
<
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:LinearAxis
/>
</
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:DateTimeContinuousAxis
LabelFitMode
=
"Rotate"
LabelFormat
=
"MMM-dd"
/>
</
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:RadCartesianChart.SeriesProvider
>
<
telerik:ChartSeriesProvider
Source
=
"{StaticResource NewList}"
>
<
telerik:ChartSeriesProvider.SeriesDescriptors
>
<
telerik:CategoricalSeriesDescriptor
ItemsSourcePath
=
"Data"
TypePath
=
"SeriesType"
CategoryPath
=
"Date"
ValuePath
=
"Value"
/>
</
telerik:ChartSeriesProvider.SeriesDescriptors
>
</
telerik:ChartSeriesProvider
>
</
telerik:RadCartesianChart.SeriesProvider
>
</
telerik:RadCartesianChart
>
</
Grid
>
</
Window
>
And the ViewModel:
namespace
TwoDynamic
{
public
class
DataPoint
{
public
DateTime Date {
get
;
set
; }
public
double
Value {
get
;
set
; }
}
public
class
SeriesBase
{
public
ObservableCollection<DataPoint> Data {
get
;
set
; }
public
Type SeriesType {
get
{
return
SeriesTypeOverride; } }
public
virtual
Type SeriesTypeOverride {
get
{
return
null
; } }
}
public
class
PointData : SeriesBase
{
public
override
Type SeriesTypeOverride {
get
{
return
typeof
(BarSeries); } }
}
public
class
LineData : SeriesBase
{
public
override
Type SeriesTypeOverride {
get
{
return
typeof
(LineSeries); } }
}
public
class
ViewModel
{
private
Random _Random =
new
Random();
public
ObservableCollection<SeriesBase> Series1 {
get
;
private
set
; }
public
ObservableCollection<SeriesBase> Series2 {
get
;
private
set
; }
public
ViewModel()
{
Series1 =
new
ObservableCollection<SeriesBase>();
Series1.Add(
new
PointData() { Data = GenerateSomeData() });
Series1.Add(
new
PointData() { Data = GenerateSomeData() });
Series2 =
new
ObservableCollection<SeriesBase>();
Series2.Add(
new
LineData() { Data = GenerateSomeData() });
Series2.Add(
new
LineData() { Data = GenerateSomeData() });
}
private
ObservableCollection<DataPoint> GenerateSomeData()
{
ObservableCollection<DataPoint> newCollection =
new
ObservableCollection<DataPoint>();
for
(
int
i = 0; i < 10; i++)
newCollection.Add(
new
DataPoint() { Date =
new
DateTime(2012, 12, 31).AddDays(i), Value = _Random.Next(100) });
return
newCollection;
}
}
}