I have a ViewModel object with multiple properties I want to plot (such as Value1 and Value2 in DualSample below). I currently have this working with a SeriesProvider that includes a different SeriesDescriptor and ValueBinding for each property, but using the same ItemsSourcePath.
However, I now have some data sets to plot that have a different sample arrangement (such as only having Value1 in SingleSample, and missing Value2). If I try to use the existing SeriesProvider definition, I get an exception because the SensorValue2Binding doesn't work since the sample is a different type. I was going to change this to use a SeriesDescriptorSelector, but I don't see how to get multiple series from a single ViewModel object as before. The only solution I see is to create separate lists for each property I want to plot, but I'd rather avoid that is I can, mostly to help save on memory usage.
ViewModel definition:
public
interface
ISample
{
}
// Would like to plot this on the same chart as DualSample
public
class
SingleSample : ISample
{
public
Double Value1;
public
DateTime Timestamp;
}
// This is currently working
public
class
DualSample : ISample
{
public
Double Value1;
public
Double Value2;
public
DateTime Timestamp;
}
public
class
Sensor
{
// A Sensor might have a set of DualSample values, or a set of SingleSample values, but not both.
public
ObservableCollection<ISample> SensorData;
}
Currently working solution for DualSample only:
<!-- Existing solution that working with DualSample only -->
<
telerik:RadCartesianChart.SeriesProvider
>
<
telerik:ChartSeriesProvider
Source
=
"{Binding SensorList}"
>
<!-- When SensorData includes DualSample values, both series descriptors below are used,
so I get series for both Value1 and Value2 -->
<
telerik:ChartSeriesProvider.SeriesDescriptors
>
<
telerik:CategoricalSeriesDescriptor
ItemsSourcePath
=
"SensorData"
>
<
telerik:CategoricalSeriesDescriptor.Style
>
<
Style
TargetType
=
"telerik:LineSeries"
BasedOn
=
"{StaticResource {x:Type telerik:LineSeries}}"
>
<
Setter
Property
=
"ValueBinding"
Value
=
"{StaticResource SensorValue1Binding}"
/>
<
Setter
Property
=
"VerticalAxis"
Value
=
"{StaticResource Value1Axis}"
/>
</
Style
>
</
telerik:CategoricalSeriesDescriptor.Style
>
</
telerik:CategoricalSeriesDescriptor
>
<!-- If I have a SensorData collection of SingleSamples, the SensorValue2Binding values
and the plot crashes with the following ArgumentException:
"The value Telerik.Windows.Controls.ChartView.LineSeries is not of type
Telerik.Windows.Controls.ChartView.CartesianSeries and cannot be used in this generic collection"
<
telerik:CategoricalSeriesDescriptor
ItemsSourcePath
=
"SensorData"
>
<
telerik:CategoricalSeriesDescriptor.Style
>
<
Style
TargetType
=
"telerik:LineSeries"
BasedOn
=
"{StaticResource {x:Type telerik:LineSeries}}"
>
<
Setter
Property
=
"ValueBinding"
Value
=
"{StaticResource SensorValue2Binding}"
/>
<
Setter
Property
=
"VerticalAxis"
Value
=
"{StaticResource Value2Axis}"
/>
</
Style
>
</
telerik:CategoricalSeriesDescriptor.Style
>
</
telerik:CategoricalSeriesDescriptor
>
</
telerik:ChartSeriesProvider.SeriesDescriptors
>
</
telerik:ChartSeriesProvider
>
</
telerik:RadCartesianChart.SeriesProvider
>
Attempted solution to work with both DualSample and SingleSample:
<!-- Attempted solution that I would like to work with both DualSample and SingleSample data sets -->
<
telerik:RadCartesianChart.SeriesProvider
>
<
telerik:ChartSeriesProvider
Source
=
"{Binding SensorList}"
>
<
telerik:ChartSeriesProvider.SeriesDescriptorSelector
>
<
local:MySeriesDescriptorSelector
>
<
local:MySeriesDescriptorSelector.Value1SeriesDescriptor
>
<
telerik:CategoricalSeriesDescriptor
ItemsSourcePath
=
"SensorData"
>
<
telerik:CategoricalSeriesDescriptor.Style
>
<
Style
TargetType
=
"telerik:LineSeries"
BasedOn
=
"{StaticResource {x:Type telerik:LineSeries}}"
>
<
Setter
Property
=
"ValueBinding"
Value
=
"{StaticResource SensorValue1Binding}"
/>
<
Setter
Property
=
"VerticalAxis"
Value
=
"{StaticResource Value1Axis}"
/>
</
Style
>
</
telerik:CategoricalSeriesDescriptor.Style
>
</
telerik:CategoricalSeriesDescriptor
>
</
local:MySeriesDescriptorSelector.Value1SeriesDescriptor
>
<
local:MySeriesDescriptorSelector.Value2SeriesDescriptor
>
<
telerik:CategoricalSeriesDescriptor
ItemsSourcePath
=
"SensorData"
>
<
telerik:CategoricalSeriesDescriptor.Style
>
<
Style
TargetType
=
"telerik:LineSeries"
BasedOn
=
"{StaticResource {x:Type telerik:LineSeries}}"
>
<
Setter
Property
=
"ValueBinding"
Value
=
"{StaticResource SensorValue2Binding}"
/>
<
Setter
Property
=
"VerticalAxis"
Value
=
"{StaticResource Value2Axis}"
/>
</
Style
>
</
telerik:CategoricalSeriesDescriptor.Style
>
</
telerik:CategoricalSeriesDescriptor
>
</
local:MySeriesDescriptorSelector.Value2SeriesDescriptor
>
</
local:MySeriesDescriptorSelector
>
</
telerik:ChartSeriesProvider.SeriesDescriptorSelector
>
</
telerik:ChartSeriesProvider
>
</
telerik:RadCartesianChart.SeriesProvider
>
Any suggestions? Or is my only option to extract my Value1 and Value2 properties into separate lists?