Search code examples
c#asp.netvisual-studio-2012ajaxcontroltoolkitpie-chart

AjaxControlToolkit PieChart graphic does not render if only one data value is added


I enter data dynamically from the code behind:

PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
{
Category = "1",
Data = count1
});

It supposed to reflect the number of ratings from 1-10 by the use of a switch (I didn't show the entire switch because that would be too cumbersome). So in this case, if one person gives a rating of 1, count1 = 1, and I want the pie chart to reflect that, but instead the control remains blank and only has a 1 all the way at the corner, but the legend is still there.

Is this a bug or am I missing something?

UPDATE: Here is the switch which goes through the ratings 1 - 10 and adds the amount of that particular rating to the chart:

for (int i = 1; i <= 10; i++)
                {
                    switch (i)
                    {
                        case 1:
                            if (count1 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "1",
                                    Data = count1
                                });
                            }
                            break;
                        case 2:
                            if (count2 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "2",
                                    Data = count2
                                });
                            }
                            break;
                        case 3:
                            if (count3 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "3",
                                    Data = count3
                                });
                            }
                            break;
                        case 4:
                            if (count4 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "4",
                                    Data = count4
                                });
                            }
                            break;
                        case 5:
                            if (count5 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "5",
                                    Data = count5
                                });
                            }
                            break;
                        case 6:
                            if (count6 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "6",
                                    Data = count6
                                });
                            }
                            break;
                        case 7:
                            if (count7 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "7",
                                    Data = count7
                                });
                            }
                            break;
                        case 8:
                            if (count8 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "8",
                                    Data = count8
                                });
                            }
                            break;
                        case 9:
                            if (count9 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "9",
                                    Data = count9
                                });
                            }
                            break;
                        case 10:
                            if (count10 > 0)
                            {
                                PieChart1.PieChartValues.Add(new AjaxControlToolkit.PieChartValue
                                {
                                    Category = "10",
                                    Data = count10
                                });
                            }
                            break;
                    }

Solution

  • You are doing everything right, but PieChart does not produce valid SVG markup when there is a single value in a series, so you see nothing in result.