I'm trying to create a list of charts, widgets, that are being bound based off of data coming back from the database. Given that the DataPoints, ChartType, and also the number of DataSeries are dynamic in every way, I've come up with a solution to use a DataTemplate that has a RadChart object and on that chart I set the SeriesMappings property by running the object through a Converter. The converter then returns back a SeriesMappingCollection, which I thought should be good, but instead the graph plots two points, 8 & 5 which happen to be the Capacity and Count (respectively) of the bound object. We've tried to get this to work for most of the day with no luck. One last thing, we did test to ensure the mappings work in straight XAML and it does, so we were able to rule that out as well. If anyone has any thoughts on this, that would be much appreciated.
RadChart within the DataTemplate:
RadChart within the DataTemplate:
<
telerik:RadChart
Grid.Row
=
"1"
SeriesMappings
=
"{Binding Path=., Converter={StaticResource WidgetObjToSeriesMappingConverter}}"
ItemsSource
=
"{Binding Path=DataSeriesRoot}"
/>
public
class
WidgetObjToSeriesMappingConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
if
(value ==
null
)
return
null
;
var seriesMappingCol =
new
SeriesMappingCollection();
var barChartWidget = (BarChartWidget)value;
//Loop through each series, and configure
for
(
int
i = 0; i < barChartWidget.DataSeriesRoot.Count; i++)
{
var seriesMapping =
new
SeriesMapping();
//Check what type of chart it will be
if
(value.GetType() ==
typeof
(BarChartWidget))
seriesMapping.SeriesDefinition =
new
BarSeriesDefinition();
seriesMapping.CollectionIndex = i;
seriesMapping.SeriesDefinition.ShowItemLabels =
false
;
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"XValue"
, DataPointMember.XCategory));
seriesMapping.ItemMappings.Add(
new
ItemMapping(
"YValue"
, DataPointMember.YValue));
//Add the series to the collection
seriesMappingCol.Add(seriesMapping);
}
//Return SeriesMapping collection object
return
seriesMappingCol;
}
object
IValueConverter.ConvertBack(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
throw
new
NotImplementedException();
}
}