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

Pie Chart creation at Run-Time not working

1 Answer 74 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Francois
Top achievements
Rank 1
Francois asked on 05 Mar 2014, 12:21 PM

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
06. 
07.        Dim HBHSeries As New PieSeries
08.        HBHSeries.Name = "HBH1"
09.        HBHSeries.TooltipsAppearance.DataFormatString = "{0}"
10.        HBHSeries.LabelsAppearance.Visible = True
11. 
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
18. 
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}"
23. 
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,
Francois





1 Answer, 1 is accepted

Sort by
0
Accepted
Stamo Gochev
Telerik team
answered on 10 Mar 2014, 07:01 AM
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"))
    HBHSeries.Items.Add(item)
Next
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.

Regards,
Stamo Gochev
Telerik

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

Tags
Chart (Obsolete)
Asked by
Francois
Top achievements
Rank 1
Answers by
Stamo Gochev
Telerik team
Share this question
or