php 数据统计图类实例代码详解_PHP教程
풀어 주다: 2016-07-13 17:40:52
- /***
- * 时间 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;
http://www.bkjia.com/PHPjc/486183.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486183.htmlTechArticle?php /*** * 时间 2010-8-9 * www.ite5e.com * 注意:如有什么问题可以回帖。 * 程序最底下有调用测试代码。 ***/ define("DEFAULT_FONT_PATH", "c:/windows/fonts/...
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31