免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2799 | 回复: 1
打印 上一主题 下一主题

php绘图(花),饼图 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-20 23:07 |只看该作者 |倒序浏览


php绘图(花),饼图










Php代码
  1. 1.header("Content-type:image/png");//向浏览器输出文件头  
  2. 2.$im=imagecreate(400, 400);  
  3. 3.$yellow=imagecolorallocate($im, 255, 255, 180);  
  4. 4.$blue=imagecolorallocate($im, 0,0,255);  
  5. 5.$red=imagecolorallocate($im, 255,0,0);  
  6. 6.for ($i = 1; $i < 360; $i++) {  
  7. 7.    $temp=150*sin(2*deg2rad($i));  
  8. 8.    $x=$temp*cos(deg2rad($i))+200;  
  9. 9.    $y=$temp*sin(deg2rad($i))+200;  
  10. 10.    imagesetpixel($im, $x, $y, $red);  
  11. 11.    $temp=150*cos(2*deg2rad($i));  
  12. 12.    $x=$temp*cos(deg2rad($i))+200;  
  13. 13.    $y=$temp*sin(deg2rad($i))+200;  
  14. 14.    imagesetpixel($im, $x, $y, $blue);  
  15. 15.}  
  16. 16.imagepng($im);//输出png图像  
  17. 17.imagedestroy($im);//销毁图像资源,因其占用内存  
复制代码
//php绘制饼图



Php代码
  1. 1.<?php  
  2. 2.function pie2d($a) {  
  3. 3.    $im = imagecreate ( 420, 300 );  
  4. 4.    $back = imagecolorallocate ( $im, 255, 255, 200 );  
  5. 5.    $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 ) );  
  6. 6.    $value_a = array_values ( $a );  
  7. 7.    $all = array_sum ( $value_a );  
  8. 8.    $i = 0;  
  9. 9.    foreach ( $a as $key => $value ) {  
  10. 10.        $angle [] = $value / $all * 360;  
  11. 11.        $str = $key . ":" . round ( $value / $all * 100, 2 ) . "%";  
  12. 12.        imagestring ( $im, 5, 10, ($i * 20 + 10), $str, $color [$i] );  
  13. 13.        $i ++;  
  14. 14.    }  
  15. 15.    $s = 0;  
  16. 16.    $i = 0;  
  17. 17.    foreach ( $angle as $temp ) {  
  18. 18.        imagefilledarc ( $im, 285, 150, 240, 240, $s, $s + $temp, $color [$i], 4 );  
  19. 19.        $s += $temp;  
  20. 20.        $i ++;  
  21. 21.    }  
  22. 22.    header ( 'Content-type:image/png' );  
  23. 23.    imagepng ( $im );  
  24. 24.    imagedestroy ( $im );  
  25. 25.}  
  26. 26.$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 );  
  27. 27.$re = pie2d ( $arr );  
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-12-21 21:50 |只看该作者
学习鸟 谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP