Ďalší spôsob ako generovať koláčový graf z PHP.

<?
 
function roundoff ($v) { 
    if ( $v - floor($v) >= 0.5) { 
      return(ceil($v)); 
    } else { 
      return(floor($v)); 
    } 
  } 
 
 
function get_xy_factors ($degrees) { 
    $x = cos((3.1415926* $degrees) / doubleval(180)); 
    $y = sin((3.1415926* $degrees) / doubleval(180)); 
    return (array($x, $y)); 
  } 
 
function draw_pie($id,$rx,$ry,$r,$from,$to,$color) {
 
    ImageArc($id, $rx, $ry, $r, $r, $from, $to, $color);
 
    $axy2 = get_xy_factors($from); 
    $ax2 = floor($rx + ($axy2[0] * $r / 2)); 
    $ay2 = floor($ry + ($axy2[1] * $r / 2)); 
    ImageLine($id, $rx, $ry, $ax2, $ay2, $color); 
 
    $bxy2 = get_xy_factors($to); 
    $bx2 = ceil($rx + ($bxy2[0] * $r / 2));  
    $by2 = ceil($ry + ($bxy2[1] * $r / 2)); 
    ImageLine($id, $rx, $ry, $bx2, $by2, $color); 
 
    $xy2 = get_xy_factors((($to - $from) / 2) + $from); 
    $x2 = floor($rx + ($xy2[0] * $r /3)); 
    $y2 = floor($ry + ($xy2[1] * $r /3)); 
    ImageFilltoborder($id, $x2, $y2, $color, $color);    
}
 
function draw_legends($id,$lex,$ley,$ler,$les,$color,$balack) {
 
   ImageFilledRectangle($id, $lex, $ley, $lex+$ler, $ley+$ler, $color); 
   ImageRectangle($id, $lex, $ley, $lex+$ler, $ley+$ler,$balack);
   ImageString($id, 3, $lex+$ler+5, $ley, $les, $color);
 
}
 
function display($a,$num) {
 
 $id = imagecreate(600,400);
 
 $angle=30;
 
 $rx=120;
 $ry=130;
 
 $r=120;
 
 
 $color = ImageColorAllocate($id, 255, 255, 255);
 $balack = ImageColorAllocate($id, 0, 0, 0);
 
/*              */
 $colors=array(ImageColorAllocate($id, 255, 0, 0),
              ImageColorAllocate($id, 0, 255, 0),
              ImageColorAllocate($id, 0, 0, 255),
              ImageColorAllocate($id, 0, 255, 255),
              ImageColorAllocate($id, 255, 0, 255));
 
 $les=array("choice 1","choice 2","choice 3","choice 4","choice 5");
/*              */
 
 $lex=210;
 $ley=50;
 $ler=13;
 
 
 $sum=0;
 for($i=0;$i<$num;$i++)
  $sum=$sum+$a[$i];
 
 $from=$angle;
 $to=$from+roundoff(360*$a[0]/$sum);
 
 Imagerectangle($id, 0, 0, 440, 240, $colors[0]);
 ImageString($id, 5, 180, 10, "my test", $colors[0]);
 
 
 for($i=0;$i<$num;$i++) {
  $les[$i] .= sprintf( " <%s",$a[$i]);
  $les[$i] .= sprintf( " (%.2f%%)", ($a[$i] * 100 / doubleval($sum))); 
  draw_legends($id,$lex,$ley,$ler,$les[$i],$colors[$i],$balack);
  $ley=$ley+20;
  }
 
 for($i=0;$i<$num;$i++) {
  draw_pie($id,$rx,$ry,$r,$from,$to,$colors[$i]);
  $from=$to+1;
  $to=$from+roundoff(360*$a[$i+1]/$sum);
 }
 
 $tot="TOTAL:";
 $tot .= sprintf( " %s", $sum);
 ImageString($id, 5, 210, 200,  $tot, $colors[0]);
 
 ImagePNG($id);
 ImageDestroy($id); 
}
 
Header("Content-type: image/png");
 
 
$a[0]=15;
$a[1]=6;
$a[2]=8;
$a[3]=11;
$a[4]=9;
 
$num=5;
 
display($a,$num);
 
?>