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

Multiple Series in one Pie-Chart

3 Answers 235 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Tobias
Top achievements
Rank 1
Tobias asked on 08 Apr 2011, 07:41 AM
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

3 Answers, 1 is accepted

Sort by
0
Tobias
Top achievements
Rank 1
answered on 08 Apr 2011, 09:58 AM
Another problem is, that the circles of the legend are not filled correcty. See my attachement.
0
Accepted
Evgenia
Telerik team
answered on 13 Apr 2011, 07:32 AM
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.

0
Tobias
Top achievements
Rank 1
answered on 13 Apr 2011, 11:35 AM
Thank you for your reply. The solutions is working!
Greetings
Tags
Chart (Obsolete)
Asked by
Tobias
Top achievements
Rank 1
Answers by
Tobias
Top achievements
Rank 1
Evgenia
Telerik team
Share this question
or