Pie Chart creation at Run-Time not working

Thread is closed for posting
2 posts, 1 answers
  1. Francois
    Francois avatar
    6 posts
    Member since:
    Nov 2013

    Posted 05 Mar 2014 Link to this post

    Hello Telerik,

    Please see this code here:.

    01.Dim HBH_Chart As New RadHtmlChart
    02.        HBH_Chart.ID = "HBH_Chart"
    03.        HBH_Chart.Width = Unit.Pixel(500)
    04.        HBH_Chart.Height = Unit.Pixel(500)
    05.        HBH_Chart.Legend.Appearance.Position = HtmlChart.ChartLegendPosition.Right
    07.        Dim HBHSeries As New PieSeries
    08.        HBHSeries.Name = "HBH1"
    09.        HBHSeries.TooltipsAppearance.DataFormatString = "{0}"
    10.        HBHSeries.LabelsAppearance.Visible = True
    12.        For Each row As DataRow In dataSet.Rows
    13.            Dim item As New SeriesItem
    14.            item.YValue = row.Field(Of Integer)("AantalClienten")
    15.            item.Name = row.Field(Of String)("Naam")
    16.            item.BackgroundColor = System.Drawing.ColorTranslator.FromHtml(row.Field(Of String)("Kleur"))
    17.        Next
    19.        HBH_Chart.PlotArea.Series.Clear()
    20.        HBH_Chart.PlotArea.Series.Add(HBHSeries)
    21.        HBH_Chart.PlotArea.XAxis.DataLabelsField = "Naam"
    22.        HBH_Chart.PlotArea.YAxis.LabelsAppearance.DataFormatString = "{0}"
    24.        HtmlChartHolder.Controls.Clear()
    25.        HtmlChartHolder.Controls.Add(HBH_Chart)

    I try to create a PieChart dynamically. But the only thing that I see is that it takes up it's space in the page (i.e. the placeholder is filled). But the actual chart is not visible. It's see as a white rectangle. What am I missing here?

    Thanks a lot for your answer,

    Best regards,

  2. Answer
    Stamo Gochev
    Stamo Gochev avatar
    188 posts

    Posted 10 Mar 2014 Link to this post

    Hi Francois,

    It seems like you are creating series items in the for-each loop, but you are not adding them to the PieSeries. This could be done like this:
    For Each row As DataRow In dataSet.Rows
        Dim item As New SeriesItem
        item.YValue = row.Field(Of Integer)("AantalClienten")
        item.Name = row.Field(Of String)("Naam")
        item.BackgroundColor = System.Drawing.ColorTranslator.FromHtml(row.Field(Of String)("Kleur"))
    In addition, you should know that the Items collection is deprecated and you could use the new SeriesItems collection instead. You can find more information about it in our blog post.

    Stamo Gochev

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Back to Top