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
Did not find the solution
Contact Support