Articles in this section
Category / Section

How to bind KeyValuePair collection in WPF SfChart?

4 mins read

This guide will walk you through the steps to bind a KeyValuePair collection with the SfChart component in a WPF application.


Steps to bind the KeyValuePair collection:


Step 1: Bind the KeyValuePair collection to 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


Conclusion

I hope you enjoyed learning how to bind KeyValuePair collection in WPF SfChart.

You can refer to our WPF Chart feature tour page know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Chart Examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

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