By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

Adding Pie series to Chart

Sl1ver
100+
P: 196
I have a chart in xaml and binding data to it at the back, what im currently finding is that it adds the data to the legend but doesn't actually produce a pie chart

xaml
Expand|Select|Wrap|Line Numbers
  1. <!--Begin Custom Tab Item-->
  2.                         <sdk:TabItem  Name="CustomTabItem" Cursor="Hand" Visibility="Visible">
  3.                             <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  4.                                 <Grid.RowDefinitions>
  5.                                     <RowDefinition Height="*" MaxHeight="300" />
  6.                                     <RowDefinition Height="Auto" />
  7.                                 </Grid.RowDefinitions>
  8.                                 <charting:Chart x:Name="SamplePieChart" Title="Sample Pie Chart" BorderThickness="0"                                              
  9.                                                 MaxHeight="300"
  10.                                                 HorizontalAlignment="Stretch"
  11.                                                 VerticalContentAlignment="Top"/>
  12.                                 <TextBlock Text="This is for testing purposes" 
  13.                                     Margin="10,10,10,20" FontSize="10" TextWrapping="Wrap"
  14.                                     Grid.Row="1" />
  15.                             </Grid>
  16.                         </sdk:TabItem>
Data
Expand|Select|Wrap|Line Numbers
  1. ChartItems = new KeyValuePair<string, int>[4];
  2.  
  3.             ChartItems[0] = new KeyValuePair<string, int>("Lorem ipsum dolor sit amet", 20);
  4.             ChartItems[1] = new KeyValuePair<string, int>("Maecenas iaculis dapibus", 90);
  5.             ChartItems[2] = new KeyValuePair<string, int>("Nulla facilisi. Curabitur laoreet", 112);
  6.             ChartItems[3] = new KeyValuePair<string, int>("Pellentesque non turpis elit", 160);
Code Behind
Expand|Select|Wrap|Line Numbers
  1. Chart pie = MapApplication.Current.FindObjectInLayout("SamplePieChart") as Chart;
  2.                     pie.Series.Clear();
  3.                     var Series = new PieSeries();
  4.                     Series.ItemsSource = ChartItems;
  5.                     Series.IndependentValueBinding = new Binding("Key");
  6.                     Series.DependentValueBinding = new Binding("Value");
  7.                     pie.Series.Add(Series);
May 30 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.