• 技术文章 >php教程 >php手册

    php作线形图的函数

    2016-06-13 10:23:09原创387
    php作线形图的函数

    关键词:PHP

    /*
    函数说明
    $data:y轴数据(数组)
    $graphdata:y轴数据--百分比(数组)
    $label:x轴数据(数组)
    $height:图像高度
    $width:图像宽度
    $font:字号
    $dot:决定点的大小
    $bg:背景色
    $line :线色
    $text :文本色
    $dotcolor:点色
    $file:输出图像文件名
    */

    function qximage($data ,
    $graphdata,
    $label ,
    $height,
    $width ,
    $font,
    $dot,
    $bg,
    $line,
    $text,
    $dotcolor,
    $file)
    {
    $jc=$height/100;
    $fontwidth= imagefontwidth ($font);
    $fontheight=imagefontheight($font);

    $image= imagecreate ($width,$height+20);
    $bg= imagecolorallocate($image ,$bg[0],$bg[1],$bg[2]);
    $line=imagecolorallocate($image ,$line[0],$line[1],$line[2]);
    $text=imagecolorallocate($image ,$text[0],$text[1],$text[2]);
    $dotcolor=imagecolorallocate($image ,$dotcolor[0],$dotcolor[1],$$dotcolor[2]);
    imageline ($image,0,0,0,$height,$line);
    imageline($image,0,$height,$width,$height,$line);

    for ($i=1;$i<11;$i++)
    {
    imagedashedline($image,0,$height - $jc*$i*10 ,$width ,$height -$jc*$i*10 ,$line );
    imagestring ($image,$font,0,$height-$jc*$i*10,$i*10,$text);
    }
    for ($i=0;$i {
    #echo $tmp."
    ";
    $x1=(($width-50)/count($data))*($i)+40;
    #echo $x1 ."
    ";
    $y1=$height-$graphdata[$i]*$jc;
    $x2=$x1;
    $y2=$y1+$graphdata[$i]*$jc;
    #echo $y1."
    ";
    imagestring($image,$font,$x1,$y1-2*$fontheight,$graphdata[$i]."%(".$data[$i].")",$text);
    imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor);
    imagefilltoborder ($image,$x1,$y1,$dotcolor,$dotcolor);
    imagestring ($image,$font,$x1,$y2,$label[$i],$text);
    if ($i>0)
    {
    imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line);
    }
    $tmpx1=$x1;$tmpy1=$y1;
    }
    imagegif ($image,$file);
    }
    ?>

    php入门到就业线上直播课:查看学习

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    上一篇:如何使用PHP中的正则表达式 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• mysql 数据备份类代码• 我的论坛源代码(五)• php根据用户语言跳转相应网页• Xgcalendar 新增Php demo• PHP 采集程序原理分析篇
    1/1

    PHP中文网