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.
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.
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.