首页 > php图像处理 > php动态生成饼图代码

php动态生成饼图代码

//创建图像 
$image=imagecreatetruecolor(300,300); 
//定义画饼状图所需要的颜色 
$white=imagecolorallocate($image, 0xff, 0xff, 0xff); 
$gray=imagecolorallocate($image, 0xc0, 0xc0, 0xc0); 
$darkgray=imagecolorallocate($image, 0x90, 0x90, 0x90); 
$navy=imagecolorallocate($image, 0x00, 0x00, 0x80); 
$darknavy=imagecolorallocate($image, 0x00, 0x00, 0x50); 
$red=imagecolorallocate($image, 0xff, 0x00, 0x00); 
$darkred=imagecolorallocate($image, 0x90, 0x00, 0x00); 
 
/* 
imagecolorallocate -- 为一幅图像分配颜色   说明   int imagecolorallocate ( resource image, int red, int green, int blue)   imagecolorallocate() 返回一个标识符,代表了由给定的 rgb 成分组成的颜色。image 参数是 imagecreate() 函数的返回值。red,green 和 blue 分别是所需要的颜色的红,绿,蓝成分。这些参数是 0 到 255 的整数或者十六进制的 0x00 到 0xff。imagecolorallocate() 必须被调用以创建每一种用在 image 所代表的图像中的颜色。  
*/ 
//画图 
for($i=160;$i > 150; $i--) 
{ 
  imagefilledarc($image, 150, $i, 200, 80, 0, 45, $darknavy, img_arc_pie); 
  imagefilledarc($image, 150, $i, 200, 80, 45, 75 , $darkgray, img_arc_pie); 
  imagefilledarc($image, 150, $i, 200, 80, 75, 360 , $darkred, img_arc_pie); 
} 
imagefilledarc($image, 150, 150, 200, 80, 0, 45, $navy, img_arc_pie); 
imagefilledarc($image, 150, 150, 200, 80, 45, 75 , $gray, img_arc_pie); 
imagefilledarc($image, 150, 150, 200, 80, 75, 360 , $red, img_arc_pie); 
header('content-type: image/png'); 
imagepng($image); 
imagedestroy($image); 
/* 
imagefilledarc()函数,可以在画出椭圆弧的同时,使用指定颜色对其进行填充。使用此函数的这种功能,就可以很简单的画出一个用于统计的饼状图。下面演示imagefilledarc()函数的使用方法 
*/ 
 
//在图片画线条 
 
//创建真彩色图像 
$img=imagecreatetruecolor(300,300); 
$white=imagecolorallocate($img,255,255,255); 
$red=imagecolorallocate($img,255,0,0); 
$green=imagecolorallocate($img,0,255,0); 
//在图像上画椭圆 
imagefilledellips教程e($img,150,150,250,100,$red); 
imagefilledellipse($img,150,150,100,250,$green); 
//输出图像 
header("content-type: image/png"); 
imagepng($img); 
//销毁图像 
imagedestroy($img);


文章地址:http://www.phprm.com/tuxiang/fs4447.html

转载随意^^请带上本文地址!

标签:php生成饼图 php动态饼图

相关文章

发表留言