Multiple Series in one Pie-Chart

Thread is closed for posting
4 posts, 1 answers
  1. Tobias
    Tobias avatar
    7 posts
    Member since:
    Apr 2011

    Posted 08 Apr 2011 Link to this post

    Hallo,

    I am trying to display multiple series in one Pie-Chart with the following VB-code:
    Dim chartSeries As ChartSeries
           Dim dataset As GeschlechterverhaeltnisDataTable = GetMyData()
           Me.pie_Chart.Chart.Series.RemoveSeries()
           Me.pie_Chart.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Font = New Font("Arial", 10)
           Me.pie_Chart.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = Color.Black
           Me.pie_Chart.PlotArea.XAxis.AutoScale = False
           Me.pie_Chart.Legend.TextBlock.Appearance.TextProperties.Color = Color.LightSkyBlue
           Me.pie_Chart.Legend.Appearance.Position.AlignedPosition = AlignedPositions.Right
           For i As Integer = 0 To dataset.Count - 1
               chartSeries = New ChartSeries(dataset(i).Column1.ToString(), ChartSeriesType.Pie)
               chartSeries.AddItem(New ChartSeriesItem(dataset(i).count_result, dataset(i).count_result))
               Me.pie_Chart.Series.Add(chartSeries)
           Next
            Me.Chart_GenderRate.AddChartSerie
    s(chartSeries)
    In the result, i have a number of charts, which are equal to the "dataset.Count - 1" value.  but all values should be displayed in one chart like the second chart in the following example: Example
  2. Tobias
    Tobias avatar
    7 posts
    Member since:
    Apr 2011

    Posted 08 Apr 2011 Link to this post

    Another problem is, that the circles of the legend are not filled correcty. See my attachement.
  3. Answer
    Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 13 Apr 2011 Link to this post

    Hello Tobias,

    Each new Chart Serie added to the Chart Area creates new Pie Chart. To be able to show single Chart you should create one ChartSerie and add as much items as you need to be displayed - each ChartSeriesItem will be new Pie's slice.
    The following code sample demonstrates how to create Pie Chart from a DataTable as datasource:
     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
          Dim table As New DataTable()
          table.Columns.Add(New DataColumn("Value", GetType(Integer)))
          table.Columns.Add(New DataColumn("Name", GetType(String)))
          table.Rows.Add(New Object() { 10, "A" })
          table.Rows.Add(New Object() { 20, "B"})
          table.Rows.Add(New Object() { 30, "C"})
          Dim chartSeries1 As New ChartSeries()
          chartSeries1.DataYColumn = "Value"
          chartSeries1.DefaultLabelValue = "#Y%"
          chartSeries1.Type = Telerik.Charting.ChartSeriesType.Pie
          chartSeries1.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels
          RadChart1.AddChartSeries(chartSeries1)
          RadChart1.DataSource = table
          RadChart1.DataBind()
    End Sub
      Protected Sub RadChart1_ItemDataBound(ByVal sender As Object, ByVal e As ChartItemDataBoundEventArgs)
          e.SeriesItem.Name = (CType(e.DataItem, DataRowView))("Name").ToString()
      End Sub

    To set custom Name for the SeriesItems in Legend as in the demo mentioned by you , the ItemDataBound event of the Chart is handled and the "Name" property is set as SeriesItem.Name.

    Greetings,
    Evgenia
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  4. Tobias
    Tobias avatar
    7 posts
    Member since:
    Apr 2011

    Posted 13 Apr 2011 Link to this post

    Thank you for your reply. The solutions is working!
    Greetings
Back to Top