php 数据统计图类实例代码详解_PHP教程

php中文网
发布: 2016-07-13 17:40:52
原创
1544人浏览过

php 数据统计图类实例代码详解_PHP教程

  1. php
  2. /***
  3. * 时间 2010-8-9
  4. * www.ite5e.com
  5. * 注意:如有什么问题可以回帖。
  6. * 程序最底下有调用测试代码。
  7. ***/
  8. define("DEFAULT_FONT_PATH", "c:/windows/fonts/simhei.ttf");
  9. class barbarism
  10. {
  11.     private $_x;
  12.     private $_y;
  13.     private $_h;
  14.     public $_l = 50;
  15.     private $_w = null;
  16.     private $_srcPoints = array();
  17.     private $_points = array();
  18.     
  19.     public function __construct($x, $y, $h, $l = 50, $w = null)
  20.     {
  21.         $this->_x = $x;
  22.         $this->_y = $y;
  23.         $this->_h = $h;
  24.         $this->_l = $l;
  25.         $this->_w = $w;
  26.         $this->_srcPoints = $this->getSrcPoints();
  27.         $this->_points = $this->getPoints();
  28.     }
  29.     
  30.     public function getSrcPoints()
  31.     {
  32.         return array(
  33.             array($this->_x                 , $this->_y),
  34.             array($this->_x $this->_l       , $this->_y),
  35.             array($this->_x (1.35*$this->_l), $this->_y-(0.35*$this->_l)),
  36.             array($this->_x (0.35*$this->_l), $this->_y-(0.35*$this->_l)),
  37.             array($this->_x                 , $this->_y $this->_h),
  38.             array($this->_x $this->_l       , $this->_y $this->_h),
  39.             array($this->_x (1.35*$this->_l), $this->_y $this->_h-(0.35*$this->_l))
  40.         );
  41.     }
  42.     
  43.     public function getPoints()
  44.     {
  45.         $points = array();
  46.         foreach($this->_srcPoints as $key => $val)
  47.         {
  48.             $points[] = $val[0];
  49.             $points[] = $val[1];
  50.         }
  51.         return $points;
  52.     }
  53.     
  54.     public function getTopPoints()
  55.     {
  56.         return array_slice($this->_points, 0, 8); //顶坐标
  57.     }
  58.     
  59.     public function getBelowPoints()
  60.     {
  61.         return array_merge(array_slice($this->_points, 0, 2), array_slice($this->_points, 8, 4), array_slice($this->_points, 2, 2)); //下坐标
  62.     }
  63.     
  64.     public function getRightSidePoints()
  65.     {
  66.         return array_merge(array_slice($this->_points, 2, 2), array_slice($this->_points, 10, 4), array_slice($this->_points, 4, 2)); //右侧坐标
  67.     }
  68.     
  69.     public function draw($image, $topColor, $belowColor, $sideColor, $borderColor = null, $type = LEFT)
  70.     {
  71.         if (is_null($borderColor))
  72.         {
  73.             $borderColor = 0xcccccc;
  74.         }
  75.         
  76.         $top_rgb = $this->getRGB($topColor);
  77.         $below_rgb = $this->getRGB($belowColor);
  78.         $side_rgb = $this->getRGB($sideColor);
  79.         $top_color = imagecolorallocate($image, $top_rgb[R], $top_rgb[G], $top_rgb[B]);
  80.         $below_color = imagecolorallocate($image, $below_rgb[R], $below_rgb[G], $below_rgb[B]);
  81.         $side_color = imagecolorallocate($image, $side_rgb[R], $side_rgb[G], $side_rgb[B]);
  82.         
  83.         imagefilledpolygon($image, $this->getTopPoints(), 4, $top_color); //画顶面
  84.         imagepolygon($image, $this->getTopPoints(), 4, $borderColor); //画顶面边线
  85.         
  86.         imagefilledpolygon($image, $this->getBelowPoints(), 4, $below_color); //画下面
  87.         imagepolygon($image, $this->getBelowPoints(), 4, $borderColor); //画下面边线
  88.         
  89.         if ($type == LEFT)
  90.         {
  91.             imagefilledpolygon($image, $this->getRightSidePoints(), 4, $side_color); //画右侧面
  92.             imagepolygon($image, $this->getRightSidePoints(), 4, $borderColor); //画侧面边线
  93.         }    
  94.     }
  95.     
  96.     public function getRGB($color)
  97.     {
  98.         $ar = array();
  99.         $color = hexdec($color);
  100.         $ar[R] = ($color>>16) & 0xff;
  101.         $ar[G] = ($color>>8) & 0xff;
  102.         $ar[B] = ($color) & 0xff;
  103.         return $ar;
  104.     }
  105. }
  106. class Bardate
  107. {
  108.     private $_W;
  109.     private $_H;
  110.     private $_bgColor = "ffffff";
  111.     private $_barHeights = array();
  112.     private $_barTexts = array();
  113.     private $_barColors = array();
  114.     public $_title;
  115.     public $_paddingTop = 30;
  116.     public $_paddingBottom = 100;
  117.     public $_paddingLeft = 45;
  118.     public $_paddingRight = 2;
  119.     public $_barL = 50;
  120.     public $image;

    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486183.htmlTechArticle?php /*** * 时间 2010-8-9 * www.ite5e.com * 注意:如有什么问题可以回帖。 * 程序最底下有调用测试代码。 ***/ define("DEFAULT_FONT_PATH", "c:/windows/fonts/...
相关标签:
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号