Binding Pie chart with datatable

Thread is closed for posting
2 posts, 0 answers
  1. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 01 Jul 2011 Link to this post

    I have a datatable that has the following values

    Item   Value
    C1      12
    C2      14
    C12    25
    C24    30
    Dist     90
    site     24

    I want to create two pie charts. In the First pie chart, i want tos how the C1, C2 and c12 on the pie chart and along with the series. in the series, I want tos how C1, c2 and C12
    In the second pie chart, i want to show C24, dist and site. how can I acheive this.

    any help will be appreciated.

    Thanks

  2. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 06 Jul 2011 Link to this post

    Hello Anjali,

    Each new Chart Serie added to the Chart Area creates new Pie Chart. Create 2 ChartSeries and add as much items in the DataTable as you need to be displayed - each ChartSeriesItem will be new Pie's slice.
    The following code sample demonstrates how to create the two Pie Charts and populate their values from DataTable as datasource:

    protected void Page_Load(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add(new DataColumn("Name1", typeof(string)));
            table.Columns.Add(new DataColumn("Value1", typeof(int)));
            table.Columns.Add(new DataColumn("Name2", typeof(string)));
            table.Columns.Add(new DataColumn("Value2", typeof(int)));
      
            table.Rows.Add(new object[] { "C1", 12, "C24", 30});
            table.Rows.Add(new object[] { "C2", 14 , "Dist", 90});
            table.Rows.Add(new object[] { "C12", 25, "site", 24});
      
      
            ChartSeries chartSeries1 = new ChartSeries();
            chartSeries1.DataYColumn = "Value1";
            chartSeries1.DataLabelsColumn = "Name1";
            ChartSeries chartSeries2 = new ChartSeries();
            chartSeries2.DataYColumn = "Value2";
            chartSeries2.DataLabelsColumn = "Name2";
      
            chartSeries1.Type = ChartSeriesType.Pie;
            chartSeries2.Type = ChartSeriesType.Pie;
            RadChart1.AddChartSeries(chartSeries1);
            RadChart1.AddChartSeries(chartSeries2);
      
            RadChart1.DataSource = table;
            RadChart1.DataBind(); 
        }

    For more information about the properties used - you can review our help topic

    Regards,
    Evgenia
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top