RadPieChart binding to dictionary

2 posts, 0 answers
  1. Cliff
    Cliff avatar
    1 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2012 Link to this post

    I am new to telerik products, currently evaluating your latest RadControls. I've looked for a good sample on how to data bind to a RadPieChart but have not found one. So I'd appreciate any help.
    I would like to replace our current use of the SL toolkit PieChart with the RadPieChart. All our uses bind the pie chart defined in the xaml with a dictionary type, typically using <string, decimal> definition.  Where string(the key) is the pie label an decimal (the value) is the corresponding value.  I am looking for an easy example on how to do this with RadPieChart

    Here's a typical example of using the SL toolkit pie chart (slightly customized):
    First the xaml:

    <customControls:LabeledPieChart x:Name="minsPieChart" Title="Invoice Cost Breakdown" Height="Auto" Width="Auto" BorderBrush="DarkGray" Margin="5">
             <customControls:LabeledPieSeries ItemsSource="{Binding}"
                 Palette="{StaticResource MyPalette}"
                PieChartLabelStyle="{StaticResource pieChartLabelStyle}" LabelDisplayMode="Connected">

    In the code behind, I simply set the binding by
    Dictionary<stringdecimal> MyCostValues;
    minsPieChart.DataContext = MyCostValues

    How would I do the same with using RadPieChart control ?
    Thank you.

  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 31 Jul 2012 Link to this post

    Hi Cliff,

      Are you using RadChartView or RadChart?  RadChart has been replaced by RadChartView, to see all the advantages RadChartView has over the older RadChart, go to this link. You'll see a summary of the dramatic improvements made to the control. 

      One of the major advancements made was to the controls ability to consume data. To help you a little further, this link will bring you to the documentation on how to bind data to RadChartView. Along with that documentation, this one and this one will help show you how to bind almost any type of data to the component. In addition to the control specific documentation, I would spend a couple minutes and look at the Data Binding Overview and Consuming Data Overview documentation as well. You will learn how to bind data to any RadControl from almost any data source in there.

      You can definitely use your existing Key/Value setup and get the results you're looking for. I recommend that you pull in the Dictionary source into the ViewModel and bind it to an ObservableCollection and use the INotifyPropertyChanged interface (I would use the Key value as "Name" object and the Value value as an "Amount" object).  This will allow you just to bind the collection directly to the series data source and the RadChartView will visualize the objects directly.

    Good Luck,
Back to Top