Why does my pie chart turn into a bar chart?

3 posts, 1 answers
  1. Douglas
    Douglas avatar
    15 posts
    Member since:
    Feb 2012

    Posted 08 Mar 2012 Link to this post

    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. Answer
    Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 13 Mar 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Douglas
    Douglas avatar
    15 posts
    Member since:
    Feb 2012

    Posted 13 Mar 2012 Link to this post

    Thank you for the explanation.  I understand now.
Back to Top