header("Content-type:image/png");//向浏览器输出文件头
$im=imagecreate(400, 400);
$yellow=imagecolorallocate($im, 255, 255, 180);
$blue=imagecolorallocate($im, 0,0,255);
$red=imagecolorallocate($im, 255,0,0);
for ($i = 1; $i < 360; $i++) {
$temp=150*sin(2*deg2rad($i));
$x=$temp*cos(deg2rad($i))+200;
$y=$temp*sin(deg2rad($i))+200;
imagesetpixel($im, $x, $y, $red);
$temp=150*cos(2*deg2rad($i));
$x=$temp*cos(deg2rad($i))+200;
$y=$temp*sin(deg2rad($i))+200;
imagesetpixel($im, $x, $y, $blue);
}
imagepng($im);//输出png图像
imagedestroy($im);//销毁图像资源,因其占用内存
//php绘制饼图
<?php
function pie2d($a) {
$im = imagecreate ( 420, 300 );
$back = imagecolorallocate ( $im, 255, 255, 200 );
$color = array (imagecolorallocate ( $im, 0, 0, 255 ), imagecolorallocate ( $im, 255, 0, 0 ), imagecolorallocate ( $im, 0, 255, 0 ), imagecolorallocate ( $im, 100, 100, 255 ), imagecolorallocate ( $im, 255, 0, 255 ), imagecolorallocate ( $im, 150, 0, 0 ), imagecolorallocate ( $im, 0, 0, 150 ), imagecolorallocate ( $im, 0, 150, 0 ), imagecolorallocate ( $im, 0, 0, 0 ), imagecolorallocate ( $im, 150, 150, 150 ) );
$value_a = array_values ( $a );
$all = array_sum ( $value_a );
$i = 0;
foreach ( $a as $key => $value ) {
$angle [] = $value / $all * 360;
$str = $key . ":" . round ( $value / $all * 100, 2 ) . "%";
imagestring ( $im, 5, 10, ($i * 20 + 10), $str, $color [$i] );
$i ++;
}
$s = 0;
$i = 0;
foreach ( $angle as $temp ) {
imagefilledarc ( $im, 285, 150, 240, 240, $s, $s + $temp, $color [$i], 4 );
$s += $temp;
$i ++;
}
header ( 'Content-type:image/png' );
imagepng ( $im );
imagedestroy ( $im );
}
$arr = array ("111" => 1, "222" => 4, "333" => 5, "444" => 6, "555" => 3, "666" => 5.4, "777" => 2.6, "888" => 3.2, "999" => 1.6, "000" => 6.3 );
$re = pie2d ( $arr );