Articles in this section
Category / Section

How to bind KeyValuePair collection in WPF SfChart?

1 min read

The following steps help you bind the KeyValuePair collection with SfChart.

 

Step 1: Bind the KeyValuePair collection with the ItemsSource property of ChartSeries.

C#:

public class ViewModel
{   
    public IList<KeyValuePair<string, int>> Collection { get; set; }
 
    public ViewModel()
    {
        Collection = new List<KeyValuePair<string, int>>();
 
        Collection.Add(new KeyValuePair<string, int>("Apple", 23));
        Collection.Add(new KeyValuePair<string, int>("Orange", 45));
        Collection.Add(new KeyValuePair<string, int>("Mango", 23));
        Collection.Add(new KeyValuePair<string, int>("Guava", 34));
    }
}

 

XAML:

<chart:SfChart>
    …
    <chart:ColumnSeries ItemsSource="{Binding Collection}" />
</chart:SfChart>

 

Step 2: Set the XBindingPath and YBindingPath of ChartSeries to “Key” and “Value”, respectively.

XAML:

<chart:SfChart>
    …
    <chart:ColumnSeries ItemsSource="{Binding Collection}" 
                        XBindingPath="Key" 
                        YBindingPath="Value"
                        />
</chart:SfChart>

 

Output

KeyValuePair Binding Chart

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied