Home> php教程> php手册> body text

php动态生成饼图代码

WBOY
Release: 2016-06-13 09:48:46
Original
738 people have browsed it

*/
//创建图像
$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()函数的使用方法

该代码的执行结果如图22.8所示:
*/

//在图片画线条

//创建真彩色图像
$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);
/*
该代码的执行结果如图22.9所示:
*/

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!