Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php 数据统计图类实例代码详解_PHP教程

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

WBOY
WBOYasal
2016-07-13 17:40:521364semak imbas

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

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