亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php繪圖之生成餅狀圖的方法

 更新時間:2015年01月24日 15:15:15   投稿:shichen2014  
這篇文章主要介紹了php繪圖之生成餅狀圖的方法,涉及GD庫中imagefilledarc方法的使用技巧,需要的朋友可以參考下

本文實例講述了php繪圖之生成餅狀圖的方法。分享給大家供大家參考。具體如下:

這里要實現(xiàn)的功能是人口分布比例圖,由扇形組成一個圓,每個扇形顏色不一樣。

復制代碼 代碼如下:
<?php
$array = array("北京"=>1925,"上海"=>2016,"廣州"=>1256,"深圳"=>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));
}

//創(chuàng)建餅狀圖,由多個扇形組成
$a1=rand(0,360);
$sum = array_sum($array);
for($j=0;$j<count($arr_key);$j++){
 $a2 = $a1 + $arr_key[$j]/$sum*360;
 imagefilledarc($im,150,150,180,80,$a1,$a2,$color[$j],IMG_ARC_PIE);
 $a1 = $a2;
}

//輸出圖像
header("content-type: image/png");
imagepng($im);
//關閉
imagedestroy($im);
?>

希望本文所述對大家的php程序設計有所幫助。

相關文章

最新評論