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

Why does my pie chart turn into a bar chart?

2 Answers 45 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Douglas
Top achievements
Rank 1
Douglas asked on 08 Mar 2012, 09:18 PM
I have this chart in my xaml:
<control:RadChart MaxHeight="200" MaxWidth="200" HorizontalAlignment="Left" x:Name="Chart2">
    <control:RadChart.DefaultView>
        <chart:ChartDefaultView>
            <!--ChartArea-->
            <chart:ChartDefaultView.ChartArea>
                <!--ChartArea-->
                <chart:ChartArea x:Name="PieChart1">
                    <chart:ChartArea.DataSeries>
                        <chart:DataSeries>
                            <chart:DataSeries.Definition>
                                <chart:PieSeriesDefinition/>
                            </chart:DataSeries.Definition>
                            <chart:DataPoint YValue="15" />
                            <chart:DataPoint YValue="5" />
                            <chart:DataPoint YValue="34" />
                            <chart:DataPoint YValue="11" />
                            <chart:DataPoint YValue="15" />
                            <chart:DataPoint YValue="25" />
                        </chart:DataSeries>
                    </chart:ChartArea.DataSeries>
                </chart:ChartArea>
            </chart:ChartDefaultView.ChartArea>
        </chart:ChartDefaultView>
    </control:RadChart.DefaultView>
</control:RadChart>

And I have this in my code-behind:
private void LoadPieChartData(MyType myRow)
{
    if (myRow != null)
    {
        List<double> pieList = new List<double>();
        pieList.Add(myRow.Col1);
        pieList.Add(myRow.Col2);
        pieList.Add(myRow.Col3);
        Chart2.ItemsSource = pieList; 
    }
}


But when LoadPieChartData is called my piechart becomes a barchart.  What did I do?



2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Milev
Telerik team
answered on 13 Mar 2012, 10:37 AM
Hi,

RadChart does not support databinding and manual series population at the same time. When you set its ItemsSource property it clears any series currently present (the one you have added through the XAML) and will populate with new databound series based on the DefaultSeriesDefinition of RadChart. I see you have not set that and it by default is BarSeries so you get a bar series in the end.

If you whish to databind a pie series please set the DefaultSeriesDefinition property of RadChart.

All the best,
Vladimir Milev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Douglas
Top achievements
Rank 1
answered on 13 Mar 2012, 06:04 PM
Thank you for the explanation.  I understand now.
Tags
Chart
Asked by
Douglas
Top achievements
Rank 1
Answers by
Vladimir Milev
Telerik team
Douglas
Top achievements
Rank 1
Share this question
or