Home > Backend Development > PHP Tutorial > PHP draws a pie chart with a transparent background and the starting point is rotated to directly below the circle_PHP Tutorial

PHP draws a pie chart with a transparent background and the starting point is rotated to directly below the circle_PHP Tutorial

WBOY
Release: 2016-07-13 10:21:22
Original
879 people have browsed it

php draws a pie chart with a transparent background and the starting point is rotated to directly below the circle

/*
 * _survey 得到一个投票的圆饼图
* @access public 表示函数对外公开
* @param $_agree 同意票数
* @param $_disagree 反对票数
* return 一张统计圆饼图
* */
function _vote($_agree,$_disagree){
    //处理参数
    if($_agree==0&&$_disagree==0){
        $_vote = 270;
    }
    if($_agree==0&&$_disagree!=0){
        $_vote = 91;
    }
    if($_agree!=0&&$_disagree==0){
        $_vote = 89;
    }
    if($_agree!=0&&$_disagree!=0){
        $_vote = intval(360*($_agree/($_agree+$_disagree))+90);
    }
    //创建画布
    $_img=imagecreatetruecolor(150,100);
    //填充透明背景
    imagealphablending($_img, false);
    imagesavealpha($_img, true);
    $white = imagecolorallocatealpha($_img,255,255,255,127);
    imagefill($_img,0,0,$white);
    //创建颜色
    $_green=imagecolorallocate($_img,180,210,52);
    $_blue=imagecolorallocate($_img,83,201,237);
    $_gary=imagecolorallocate($_img,192,192,192);
    $_green1=imagecolorallocate($_img,149,178,36);
    $_blue1=imagecolorallocate($_img,41,160,193);
    $_gary1=imagecolorallocate($_img,144,144,144);
    
    for($i=60;$i>=50;$i--){
        imagefilledarc($_img,100,$i,100,50,90,$_vote,$_blue1,IMG_ARC_PIE);
        imagefilledarc($_img,100,$i,100,50,$_vote,90,$_green1,IMG_ARC_PIE); 
    }
    
    imagefilledarc($_img,100,$i,100,50,90,$_vote,$_blue,IMG_ARC_PIE);
    imagefilledarc($_img,100,$i,100,50,$_vote,90,$_green,IMG_ARC_PIE);
    
    header("content-type: image/png");
    imagepng($_img);
    imagedestroy($_img);
}
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/859804.htmlTechArticlephp draws a pie chart with a transparent background and a starting point rotated to directly below the circle/ * * _survey gets a pie chart of votes* @access public means the function is public*...
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template