Trouble Binding Pie/Doughnut Chart with Custom Legend

2 posts, 0 answers
  1. Seth
    Seth avatar
    23 posts
    Member since:
    Nov 2008

    Posted 24 Sep 2009 Link to this post

    I have a simple object that contains a list of status names and their respective counts.  I need to display a pie or doughnut chart with the legend showing each status.  However, I'm having trouble doing this through the backend code.  My logic as follows:


    SeriesMapping seriesMapping = new SeriesMapping();

     seriesMapping.SeriesDefinition =

    new DoughnutSeriesDefinition();




    ItemMapping itemMapping = new ItemMapping();



     itemMapping.DataPointMember =




     itemMapping.FieldName =










    this.charWorkOrderTypes.ItemsSource = myData;




    this.charWorkOrderTypes.DefaultView.ChartArea.Extensions.Add(new CameraExtension());

    I'd really appreciate some assistance with this code.  Also, ideally, I'd prefer to bind everything through the XAML.  If you could provide an example of that using my test scenario I'd greatly appreciate it.







  2. Velin
    Velin avatar
    391 posts

    Posted 29 Sep 2009 Link to this post

    Hi Seth,

    Please, find attached a small example demonstrating this behavior.
    To achieve this behavior you need to set up two ItemMapping instances to map the YValue and LegendLabel data point members. Here is the code behind:
    using System; 
    using System.Collections.Generic; 
    using System.Windows.Controls; 
    using Telerik.Windows.Controls.Charting; 
    namespace SilverlightApplication1 
        public partial class MainPage : UserControl 
            public MainPage() 
                SeriesMapping seriesMapping = new SeriesMapping(); 
                seriesMapping.SeriesDefinition = new DoughnutSeriesDefinition(); 
                ItemMapping itemMapping = new ItemMapping(); 
                itemMapping.DataPointMember = DataPointMember.LegendLabel; 
                itemMapping.FieldName = "S"
                ItemMapping itemMapping2 = new ItemMapping(); 
                itemMapping2.DataPointMember = DataPointMember.YValue; 
                itemMapping2.FieldName = "D"
                RadChart1.ItemsSource = A.Fill(5); 
        public class A 
            public double D { get; set; } 
            public DateTime DT { get; set; } 
            public string S { get; set; } 
            public static IEnumerable<A> Fill(int n) 
                DateTime now = DateTime.Now; 
                for (int i = 1; i <= n; i++) 
                    A a = new A() { D = iDT = now.AddDays(i) }; 
                    aa.S = a.DT.ToShortDateString(); 
                    yield return a; 

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top