• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php GD绘制24小时柱状图_php技巧

php 搞代码 4年前 (2022-01-26) 24次浏览 已收录 0个评论

80,250,430,134,35,60,233,90,263,225,120,59,151,677,340,221,550,300,229,97,230,123,133,87 一共24个数字 一个都不能少哦少了要出错 你可以修改函数判断一下

<?PHP     <BR>/*    <BR>24小时柱状图    <BR>作者:taokey    <BR>QQ:29611705    <BR>*/    <br><br>function h24($str){     <br><br>        $hour = explode(",",$str);     <BR>        $hmax = max($hour);     <BR>        $ppix = 150/$hmax;     <br><br>        //计算柱状图高度     <BR>        $h0 = 190-$hour[0]*$ppix;     <BR>        $h1 = 190-$hour[1]*$ppix;     <BR>        $h2 = 190-$hour[2]*$ppix;     <BR>        $h3 = 190-$hour[3]*$ppix;     <BR>        $h4 = 190-$hour[4]*$ppix;     <BR>        $h5 = 190-$hour[5]*$ppix;     <BR>        $h6 = 190-$hour[6]*$ppix;     <BR>        $h7 = 190-$hour[7]*$ppix;     <BR>        $h8 = 190-$hour[8]*$ppix;     <BR>        $h9 = 190-$hour[9]*$ppix;     <BR>        $h10 = 190-$hour[10]*$ppix;     <BR>        $h11 = 190-$hour[11]*$ppix;     <BR>        $h12 = 190-$hour[12]*$ppix;     <BR>        $h13 = 190-$hour[13]*$ppix;     <BR>        $h14 = 190-$hour[14]*$ppix;     <BR>        $h15 = 190-$hour[15]*$ppix;     <BR>        $h16 = 190-$hour[16]*$ppix;     <BR>        $h17 = 190-$hour[17]*$ppix;     <BR>        $h18 = 190-$hour[18]*$ppix;     <BR>        $h19 = 190-$hour[19]*$ppix;     <BR>        $h20 = 190-$hour[20]*$ppix;     <BR>        $h21 = 190-$hour[21]*$ppix;     <BR>        $h22 = 190-$hour[22]*$ppix;     <BR>        $h23 = 190-$hour[23]*$ppix;     <br><br>        //创建一个img     <BR>        $img = imagecreate(755,210);     <BR>        //背景     <BR>        $bgc = imagecolorallocate ($img, 245, 250, 254);     <BR>        //黑色     <BR>        $bc = imagecolorallocate($img,0,0,0);     <BR>        //画竖轴     <BR>        imageline($img,15,30,15,189, $bc);     <BR>        //画横轴     <BR>        imageline($img,15,190,750,190, $bc);     <br><br>        //画竖轴点     <BR>        for($i=39,$j=10;$i<189;$i=$i+15,$j--){     <BR>                imageline($img,13,$i,15,$i, $bc);     <BR>                imagestring($img,1,1,$i-4,$j."x", $bc);     <BR>        }     <br><br>        //画横轴点     <BR>        $t = true;     <BR>        for($i=31,$j=29;$i<750;$i=$j+1,$j=$j+15){     <BR>                if($t){     <BR>                        $x=$i;     <BR>                        $t=false;     <BR>                }else{     <BR>                        $x=$i+1;     <BR>                        $t=true;     <BR>                }     <BR>                imageline($img,$x,190,$x,192, $bc);     <BR>        }     <BR>        //竖轴标记     <BR>        $x = ceil($hmax/10);     <BR>        imagestring($img,2,10,15,"X=".$x,$bc);     <BR>        //竖轴标记     <br><br>        //0点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,31,$h0,45,189,$color);     <BR>        imagestring($img,1,31,$h0-10,$hour[0],$color);     <BR>        imagechar($img,1,36,195,0,$bc);     <br><br>        //1点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,61,$h1,75,189,$color);     <BR>        imagestring($img,1,61,$h1-10,$hour[1],$color);     <BR>        imagechar($img,1,66,195,1,$bc);     <br><br>        //2点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,91,$h2,105,189,$color);     <BR>        imagestring($img,1,91,$h2-10,$hour[2],$color);     <BR>        imagechar($img,1,96,195,2,$bc);     <br><br>        //3点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,121,$h3,135,189,$color);     <BR>        imagestring($img,1,121,$h3-10,$hour[3],$color);     <BR>        imagechar($img,1,126,195,3,$bc);     <br><br>        //4点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,151,$h4,165,189,$color);     <BR>        imagestring($img,1,151,$h4-10,$hour[4],$color);     <BR>        imagechar($img,1,156,195,4,$bc);     <br><br>        //5点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,181,$h5,195,189,$color);     <BR>        imagestring($img,1,181,$h5-10,$hour[5],$color);     <BR>        imagechar($img,1,186,195,5,$bc);     <br><br>        //6点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,211,$h6,225,189,$color);     <BR>        imagestring($img,1,211,$h6-10,$hour[6],$color);     <BR>        imagechar($img,1,216,195,6,$bc);     <br><br>        //7点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,241,$h7,255,189,$color);     <BR>        imagestring($img,1,241,$h7-10,$hour[7],$color);     <BR>        imagechar($img,1,246,195,7,$bc);     <br><br>        //8点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,271,$h8,285,189,$color);     <BR>        imagestring($img,1,271,$h8-10,$hour[8],$color);     <BR>        imagechar($img,1,276,195,8,$bc);     <br><br>        //9点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,301,$h9,315,189,$color);     <BR>        imagestring($img,1,301,$h9-10,$hour[9],$color);     <BR>        imagechar($img,1,306,195,9,$bc);     <br><br>        //10点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,331,$h10,345,189,$color);     <BR>        imagestring($img,1,331,$h10-10,$hour[10],$color);     <BR>        imagestring($img,1,334,195,10,$bc);     <br><br>        //11点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,361,$h11,375,189,$color);     <BR>        imagestring($img,1,361,$h11-10,$hour[11],$color);     <BR>        imagestring($img,1,364,195,11,$bc);     <br><br>        //12点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,391,$h12,405,189,$color);     <BR>        imagestring($img,1,391,$h12-10,$hour[12],$color);     <BR>        imagestring($img,1,394,195,12,$bc);     <br><br>        //13点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,421,$h13,435,189,$color);     <BR>        imagestring($img,1,421,$h13-10,$hour[13],$color);     <BR>        imagestring($img,1,424,195,13,$bc);     <br><br>        //14点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,451,$h14,465,189,$color);     <BR>        imagestring($img,1,451,$h14-10,$hour[14],$color);     <BR>        imagestring($img,1,454,195,14,$bc);     <br><br>        //15点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,481,$h15,495,189,$color);     <BR>        imagestring($img,1,481,$h15-10,$hour[15],$color);     <BR>        imagestring($img,1,481,195,15,$bc);     <br><br>        //16点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,511,$h16,525,189,$color);     <BR>        imagestring($img,1,511,$h16-10,$hour[16],$color);     <BR>        imagestring($img,1,511,195,16,$bc);     <br><br>        //17点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,541,$h17,555,189,$color);     <BR>        imagestring($img,1,541,$h17-10,$hour[17],$color);     <BR>        imagestring($img,1,544,195,17,$bc);     <br><br>        //18点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,571,$h18,585,189,$color);     <BR>        imagestring($img,1,571,$h18-10,$hour[18],$color);     <BR>        imagestring($img,1,571,195,18,$bc);     <br><br>        //19点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,601,$h19,615,189,$color);     <BR>        imagestring($img,1,601,$h19-10,$hour[19],$color);     <BR>        imagestring($img,1,604,195,19,$bc);     <br><br>        //20点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,631,$h20,645,189,$color);     <BR>        imagestring($img,1,631,$h20-10,$hour[20],$color);     <BR>        imagestring($img,1,634,195,20,$bc);     <br><br>        //21点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,661,$h21,675,189,$color);     <BR>        imagestring($img,1,661,$h21-10,$hour[21],$color);     <BR>        imagestring($img,1,664,195,21,$bc);     <br><br>        //22点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,691,$h22,705,189,$color);     <BR>        imagestring($img,1,691,$h22-10,$hour[22],$color);     <BR>        imagestring($img,1,694,195,22,$bc);     <br><br>        //23点     <BR>        $color = imagecolorallocate($img, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));     <BR>        imagefilledrectangle($img,721,$h23,735,189,$color);     <BR>        imagestring($img,1,721,$h23-10,$hour[23],$color);     <BR>        imagestring($img,1,724,195,23,$bc);     <br><br>        //加个边框 加了之后不好看     <BR>        //imagerectangle($img, 0, 0, 754, 209, $bc);     <br><br>        imagepng($img);     <BR>        imagedestroy($img);             <BR>}     <BR>$str = isset($_GET['str'])?$_GET['str']:"";     <BR>if($str){     <BR>        h24($str);     <BR>}     <BR>?><BR><a style="color:transparent">来@源gao*daima.com搞@代#码网</a><strong>搞gaodaima代码</strong>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php GD绘制24小时柱状图_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址