Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
515
XamDataChart - Bind to List of Dictionary
posted

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);

    list.Add(d);

 

    return list;

}

Thanks.

 

Parents
  • 415
    Offline posted

    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));

          Add(new KeyValuePair<string, decimal>("Data item One", 100.0));

          Add(new KeyValuePair<string, decimal>("Data item One", 100.0));

          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.

Reply Children
No Data