php繪圖之生成餅狀圖的方法
本文實例講述了php繪圖之生成餅狀圖的方法。分享給大家供大家參考。具體如下:
這里要實現(xiàn)的功能是人口分布比例圖,由扇形組成一個圓,每個扇形顏色不一樣。
$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程序設計有所幫助。
相關文章
php判斷某個方法是否存在函數(shù)function_exists (),method_exists()與is_callabl
這篇文章主要介紹了php判斷某個方法是否存在函數(shù)function_exists (),method_exists()與is_callable()區(qū)別與用法,結合實例形式分析了php function_exists (),method_exists()與is_callable()基本功能、用法、區(qū)別與操作注意事項,需要的朋友可以參考下2020-04-04PHP使用PHPexcel導入導出數(shù)據(jù)的方法
這篇文章主要介紹了PHP使用PHPexcel導入導出數(shù)據(jù)的方法,以實例形式較為詳細的分析了PHP使用PHPexcel實現(xiàn)數(shù)據(jù)的導入與導出操作相關技巧,需要的朋友可以參考下2015-11-11PHP中file_exists函數(shù)不支持中文名的解決方法
這篇文章主要介紹了PHP中file_exists函數(shù)不支持中文名的解決方法,很實用的技巧,需要的朋友可以參考下2014-07-07PHP syntax error, unexpected $end 錯誤的一種原因及解決
PHP 遇到 syntax error, unexpected $end 錯誤時,查錯思路其實還是看看文件里 PHP 的開始標記和結束標記是否配對,還要額外注意注釋里是否出現(xiàn)過 ?> 喲。2008-10-10