php绘图(花),饼图


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 );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值