I have a situation in which a reporting service returns generic lists of data as List<Dictionary<string, object>>, where string is the column/data member name I wish to bind to, and object is the value/data point.
Is it possible to bind such a data source to the XamDataChart X and Y Axis definitions?
Here's an example of what the data source would return:
public static List<Dictionary<string, object>> GetDictionarySource()
{
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
var d = new Dictionary<string, object>();
d.Add("Name", "blah");
d.Add("YValue1", 80000);
d.Add("YValue2", 75000);
list.Add(d);
d = new Dictionary<string, object>();
d.Add("Name", "blah1");
d.Add("YValue1", 70000);
d.Add("YValue2", 65399);
return list;
}
Thanks.
Hi Louis,
could you pls also post the whole xaml chunk of the Chart control? I'm particularly interessted in the way the bindings are defined (for the X & Y axis, for the StackedBarSeries and for the StackedFragmentSeries), considering the datasource is of the type: ObservableCollection<KeyValuePair<string, double>>.
To give you a bit more details over my case, I want to display in a single stacked bar a variable number of fragments, the X axis containing hours (0 - 24) and the Value of each keyvalue pair containing a fractional number of hours (timespan). The Key string indicates the "type" of that specific timespan, and all the timespans sharing the same "type" should be represented with the same color.
Thanks!
Hi Luis,
Thanks for taking the time to share this with the community, I am sure it will be useful to other users as well.
I know this is very old but this post helped me think of a proper solution to my problem.
Might I suggest using an ObservableCollection of KeyValuePair objects. Define like so:
MyDataCollection : ObservableCollection<KeyValuePair<string, object>>
MyData : MyDataCollection
public MyData()
Add(new KeyValuePair<string, decimal>("Data item One", 100.0));
Then in your XAML file just point the ValueMemberPath to "Value" and the Label on your chart to the "Key" property of your KeyValuePairs.
Just a thought.
Petar,
Thanks for the follow-up. Since the current release doesn't support binding to a list of dictionaries, we had to come up with an alternative solution that involves converting each dictionary item into a predefined generic class and then binding to a list of these classes.
Hopefully the next release will provision for dictionary binding.
Regards,
John
Hi John,
I am just checking if there is anything else can assist you with regarding this matter.