搜索
首页php教程php手册PHP的生成条形图

PHP的生成条形图

Jun 13, 2016 am 11:23 AM
php例子广东条形图生成这个需求

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);

  // 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 ;

  // 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);
?>


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

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具