Problem adding SeriesMappings via Converter

2 posts, 0 answers
  1. Brandon
    Brandon avatar
    1 posts
    Member since:
    Feb 2012

    Posted 22 Feb 2012 Link to this post

    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:
    <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
                //Return SeriesMapping collection object
                return seriesMappingCol;
            object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
                throw new NotImplementedException();
  2. Ves
    Ves avatar
    2916 posts

    Posted 27 Feb 2012 Link to this post

    Hi Brandon,

    Indeed, it seems there is a problem in this scenario. Luckily, the workaround is simple -- wrapping the chart into a UserControl does the trick. I have attached a small example, which follows your description and works fine on my end.

    Best regards,
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top