0

I have a problem with my pie chart when I have 0 values $MyData->addPoints(array(10,20,20,15,23),"Data");
This works fine and converts to percentages across a pie chart however if any of these values are 0 which could happen as I'm dealing with counts and these are really variables in my script) then everything screws up and the color of the legend don't correlate with the data values. Basically in the pie chart the color palette only assigns a value to non 0 points

10    $PieChart->setSliceColor(0,array("R"=>48,"G"=>199,"B"=>13));
20    $PieChart->setSliceColor(1,array("R"=>246,"G"=>2,"B"=>8));
20    $PieChart->setSliceColor(2,array("R"=>233,"G"=>215,"B"=>59));  
15    $PieChart->setSliceColor(3,array("R"=>38,"G"=>42,"B"=>191));       
23    $PieChart->setSliceColor(3,array("R"=>38,"G"=>42,"B"=>191));       



10    $PieChart->setSliceColor(0,array("R"=>48,"G"=>199,"B"=>13));
0     
20    $PieChart->setSliceColor(1,array("R"=>246,"G"=>2,"B"=>8));
15    $PieChart->setSliceColor(2,array("R"=>233,"G"=>215,"B"=>59));  
23    $PieChart->setSliceColor(3,array("R"=>38,"G"=>42,"B"=>191));       
     $PieChart->setSliceColor(3,array("R"=>38,"G"=>42,"B"=>191));    

Is this a common problem?

skaffman
  • 398,947
  • 96
  • 818
  • 769
user391986
  • 29,536
  • 39
  • 126
  • 205

3 Answers3

1

I used a quick hack to bypass this bug, try to replace your zero values by -0.0001.

guest
  • 26
  • 1
  • I get the following error when I use -0.001. What I did instead if I add +0.0001 to all fields no matter the value. That seems to work fine although it makes the piechart not 100% accurate as you still see the border of the section for values which should really be 0. A PHP Error was encountered Severity: Notice Message: Undefined offset: 2 Filename: class/pPie.class.php Line Number: 467 – user391986 May 25 '11 at 13:41
1

This issue has been fixed in the latest version of pChart.

Niwata
  • 58
  • 3
0

As as work around, you can sort the values in descending and order and arrange the label accordingly.