-
-
$array = array("Beijing"=>1925,"Shanghai"=>2016,"Guangzhou"=>1256,"Shenzhen"=> 980);
- $arr_key = array_keys($array);
- $color = array();
- $im = imagecreatetruecolor(300,300);
- for($i=1;$i<=count($array);$i++ ){
- $color[] = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
- }
//Create a pie chart with multiple sectors consisting of
- $a1=rand(0,360);
- $sum = array_sum($array);
- for($j=0;$j $a2 = $a1 + $arr_key[$j]/$sum*360;
- imagefilledarc($im,150,150,180,80,$a1,$a2,$color[$j],IMG_ARC_PIE);
- $a1 = $a2;
- } // bbs .it-home.org
//Output image
- header("content-type: image/png");
- imagepng($im);
//Close
- imagedestroy($im);
- ?>
-
Copy code
|