This is a migrated thread and some comments may be shown as answers.

RadPieChart binding to dictionary

1 Answer 149 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Cliff
Top achievements
Rank 1
Cliff asked on 31 Jul 2012, 09:10 AM
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:LabeledPieChart.Series>
         <customControls:LabeledPieSeries ItemsSource="{Binding}"
 
            DependentValuePath="Value"
 
            IndependentValuePath="Key"
             Palette="{StaticResource MyPalette}"
 
            IsSelectionEnabled="False"
 
            PieChartLabelStyle="{StaticResource pieChartLabelStyle}" LabelDisplayMode="Connected">
 
        </customControls:LabeledPieSeries>
 
    </customControls:LabeledPieChart.Series>
</customControls:LabeledPieChart>


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.
Cliff.


1 Answer, 1 is accepted

Sort by
0
Lancelot
Top achievements
Rank 1
answered on 31 Jul 2012, 04:02 PM
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,
Lancelot
Tags
Chart
Asked by
Cliff
Top achievements
Rank 1
Answers by
Lancelot
Top achievements
Rank 1
Share this question
or