php 数据统计图类实例代码详解
程序员文章站
2022-05-21 13:30:36
...
- /***
- * 时间 2010-8-9
- * www.ite5e.com
- * 注意:如有什么问题可以回帖。
- * 程序最底下有调用测试代码。
- ***/
- define("DEFAULT_FONT_PATH", "c:/windows/fonts/simhei.ttf");
- class barbarism
- {
- private $_x;
- private $_y;
- private $_h;
- public $_l = 50;
- private $_w = null;
- private $_srcPoints = array();
- private $_points = array();
- public function __construct($x, $y, $h, $l = 50, $w = null)
- {
- $this->_x = $x;
- $this->_y = $y;
- $this->_h = $h;
- $this->_l = $l;
- $this->_w = $w;
- $this->_srcPoints = $this->getSrcPoints();
- $this->_points = $this->getPoints();
- }
- public function getSrcPoints()
- {
- return array(
- array($this->_x , $this->_y),
- array($this->_x $this->_l , $this->_y),
- array($this->_x (1.35*$this->_l), $this->_y-(0.35*$this->_l)),
- array($this->_x (0.35*$this->_l), $this->_y-(0.35*$this->_l)),
- array($this->_x , $this->_y $this->_h),
- array($this->_x $this->_l , $this->_y $this->_h),
- array($this->_x (1.35*$this->_l), $this->_y $this->_h-(0.35*$this->_l))
- );
- }
- public function getPoints()
- {
- $points = array();
- foreach($this->_srcPoints as $key => $val)
- {
- $points[] = $val[0];
- $points[] = $val[1];
- }
- return $points;
- }
- public function getTopPoints()
- {
- return array_slice($this->_points, 0, 8); //顶坐标
- }
- public function getBelowPoints()
- {
- return array_merge(array_slice($this->_points, 0, 2), array_slice($this->_points, 8, 4), array_slice($this->_points, 2, 2)); //下坐标
- }
- public function getRightSidePoints()
- {
- return array_merge(array_slice($this->_points, 2, 2), array_slice($this->_points, 10, 4), array_slice($this->_points, 4, 2)); //右侧坐标
- }
- public function draw($image, $topColor, $belowColor, $sideColor, $borderColor = null, $type = LEFT)
- {
- if (is_null($borderColor))
- {
- $borderColor = 0xcccccc;
- }
- $top_rgb = $this->getRGB($topColor);
- $below_rgb = $this->getRGB($belowColor);
- $side_rgb = $this->getRGB($sideColor);
- $top_color = imagecolorallocate($image, $top_rgb[R], $top_rgb[G], $top_rgb[B]);
- $below_color = imagecolorallocate($image, $below_rgb[R], $below_rgb[G], $below_rgb[B]);
- $side_color = imagecolorallocate($image, $side_rgb[R], $side_rgb[G], $side_rgb[B]);
- imagefilledpolygon($image, $this->getTopPoints(), 4, $top_color); //画顶面
- imagepolygon($image, $this->getTopPoints(), 4, $borderColor); //画顶面边线
- imagefilledpolygon($image, $this->getBelowPoints(), 4, $below_color); //画下面
- imagepolygon($image, $this->getBelowPoints(), 4, $borderColor); //画下面边线
- if ($type == LEFT)
- {
- imagefilledpolygon($image, $this->getRightSidePoints(), 4, $side_color); //画右侧面
- imagepolygon($image, $this->getRightSidePoints(), 4, $borderColor); //画侧面边线
- }
- }
- public function getRGB($color)
- {
- $ar = array();
- $color = hexdec($color);
- $ar[R] = ($color>>16) & 0xff;
- $ar[G] = ($color>>8) & 0xff;
- $ar[B] = ($color) & 0xff;
- return $ar;
- }
- }
- class Bardate
- {
- private $_W;
- private $_H;
- private $_bgColor = "ffffff";
- private $_barHeights = array();
- private $_barTexts = array();
- private $_barColors = array();
- public $_title;
- public $_paddingTop = 30;
- public $_paddingBottom = 100;
- public $_paddingLeft = 45;
- public $_paddingRight = 2;
- public $_barL = 50;
- public $image;
上一篇: php 迷宫
下一篇: 使用PHP实现二分查找算法代码分享