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
Data
Code Behind
xaml
Code:
<!--Begin Custom Tab Item--> <sdk:TabItem Name="CustomTabItem" Cursor="Hand" Visibility="Visible"> <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition Height="*" MaxHeight="300" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <charting:Chart x:Name="SamplePieChart" Title="Sample Pie Chart" BorderThickness="0" MaxHeight="300" HorizontalAlignment="Stretch" VerticalContentAlignment="Top"/> <TextBlock Text="This is for testing purposes" Margin="10,10,10,20" FontSize="10" TextWrapping="Wrap" Grid.Row="1" /> </Grid> </sdk:TabItem>
Code:
ChartItems = new KeyValuePair<string, int>[4]; ChartItems[0] = new KeyValuePair<string, int>("Lorem ipsum dolor sit amet", 20); ChartItems[1] = new KeyValuePair<string, int>("Maecenas iaculis dapibus", 90); ChartItems[2] = new KeyValuePair<string, int>("Nulla facilisi. Curabitur laoreet", 112); ChartItems[3] = new KeyValuePair<string, int>("Pellentesque non turpis elit", 160);
Code:
Chart pie = MapApplication.Current.FindObjectInLayout("SamplePieChart") as Chart; pie.Series.Clear(); var Series = new PieSeries(); Series.ItemsSource = ChartItems; Series.IndependentValueBinding = new Binding("Key"); Series.DependentValueBinding = new Binding("Value"); pie.Series.Add(Series);