PHP的生成条形图_PHP教程

php中文网
发布: 2016-07-20 11:07:06
原创
1092人浏览过

php的生成条形图
由于overwhelmning为广东的需求有关的例子,这个最重要的是产生从一个数组条形图要

求。当然,这些可以很容易地从任何来源数目,以及投入到一个数组


  // create an array of values for the chart. These values
  // could come from anywhere, POST, GET, database etc.
  $values = array(23,32,35,57,12,3,36,54,32,15,43,24,30);

  // now we get the number of values in the array. this will
  // tell us how many columns to plot
    $columns  = count($values);

立即学习PHP免费学习笔记(深入)”;

  // set the height and width of the graph image

    $width = 300;
    $height = 200;

  // Set the amount of space between each column
    $padding = 5;

  // Get the width of 1 column
    $column_width = $width / $columns ;

AI卡通生成器
AI卡通生成器

免费在线AI卡通图片生成器 | 一键将图片或文本转换成精美卡通形象

AI卡通生成器 51
查看详情 AI卡通生成器

  // set the graph color variables
    $im        = imagecreate($width,$height);
    $gray      = imagecolorallocate ($im,0xcc,0xcc,0xcc);
    $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
    $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
    $white     = imagecolorallocate ($im,0xff,0xff,0xff);

  // set the background color of the graph
    imagefilledrectangle($im,0,0,$width,$height,$white);


  // Calculate the maximum value we are going to plot
  $max_value = max($values);

  // loop over the array of columns
    for($i=0;$i        {
    // set the column hieght for each value
        $column_height = ($height / 100) * (( $values[$i] / $max_value)

*100);
    // now the coords
        $x1 = $i*$column_width;
        $y1 = $height-$column_height;
        $x2 = (($i+1)*$column_width)-$padding;
        $y2 = $height;

        // write the columns over the background
        imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);

        // This gives the columns a little 3d effect
        imageline($im,$x1,$y1,$x1,$y2,$gray_lite);
        imageline($im,$x1,$y2,$x2,$y2,$gray_lite);
        imageline($im,$x2,$y1,$x2,$y2,$gray_dark);
        }

   // set the correct png headers
   header ("Content-type: image/png");
  // spit the image out the other end
  imagepng($im);
?>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444988.htmlTechArticlePHP的生成条形图 由于overwhelmning为广东的需求有关的例子,这个最重要的是产生从一个数组条形图要 求。当然,这些可以很容易地从任何来...
相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号