This is a migrated thread and some comments may be shown as answers.

Dynamic getter is not supported for value type [KeyValuePair`2]

1 Answer 219 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
StepTNT
Top achievements
Rank 1
StepTNT asked on 26 Oct 2014, 10:36 AM
Hi there,
I'm trying the new Universal UI and I ran in this exception when binding to an ObservableDictionary<string, int>

System.ArgumentException:
Dynamic getter is not supported for value type [KeyValuePair`2]   at
Telerik.Universal.Core.DynamicHelper.CreatePropertyValueGetter(Type
type, String propertyName)   at
Telerik.Universal.UI.Xaml.Controls.Chart.PropertyNameDataPointBinding.GetValue(Object
instance)   at
Telerik.Universal.UI.Xaml.Controls.Chart.CategoricalSeriesDataSource.InitializeBinding(DataPointBindingEntry
binding)   at
Telerik.Universal.UI.Xaml.Controls.Chart.ChartSeriesDataSource.GenerateDataPoint(ObjeHere's the code that I'm using:

01.public ObservableDictionary<string, int> MyDict { get; set; }
02....
03.private void UpdateStats()
04.{
05.    MyDict.Clear();           
06.    foreach (var item in Items)
07.    {
08.        var dayString = item.When.Date.ToLocalTime().ToString();
09.        var dayKey = dayString.Split(' ')[0];
10.        MyDict[dayKey] = (MyDict.ContainsKey(dayKey)) ? MyDict[dayKey] + 1 : 1;               
11.    }
12.}


01.<chart:RadCartesianChart x:Name="lineSeries"
02.                         PaletteName="DefaultLight"
03.                         ClipToBounds="False">
04.    <chart:RadCartesianChart.VerticalAxis>
05.        <chart:LinearAxis/>
06.    </chart:RadCartesianChart.VerticalAxis>
07.    <chart:RadCartesianChart.HorizontalAxis>
08.        <chart:CategoricalAxis AutoGroup="True"
09.                               PlotMode="OnTicks"/>
10.    </chart:RadCartesianChart.HorizontalAxis>
11.    <chart:LineSeries ItemsSource="{Binding AsthmaStats}">
12.        <chart:LineSeries.CategoryBinding>
13.            <chart:PropertyNameDataPointBinding PropertyName="Key"/>
14.        </chart:LineSeries.CategoryBinding>
15.        <chart:LineSeries.ValueBinding>
16.            <chart:PropertyNameDataPointBinding PropertyName="Value"/>
17.        </chart:LineSeries.ValueBinding>
18.    </chart:LineSeries>
19.</chart:RadCartesianChart>


What's wrong with it?

1 Answer, 1 is accepted

Sort by
0
Vladislav
Telerik team
answered on 29 Oct 2014, 08:28 AM
Hi Stefano Tenuta,

currently RadChart control doesn't support direct binding to Dictionary (and ObservableDictionary).
In order to achieve a similar behavior you can bind the ItemsSource to a Collection (ObservableCollection) of your custom type, containing pair of "Keys" and "Values". 

I hope that this approach is applicable for you.

Regards,
Vladislav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Chart
Asked by
StepTNT
Top achievements
Rank 1
Answers by
Vladislav
Telerik team
Share this question
or