PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

原创
2016-07-13 17:40:52 1095浏览


  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. public function __construct($x, $y, $h, $l = 50, $w = null)
  18. {
  19. $this->_x = $x;
  20. $this->_y = $y;
  21. $this->_h = $h;
  22. $this->_l = $l;
  23. $this->_w = $w;
  24. $this->_srcPoints = $this->getSrcPoints();
  25. $this->_points = $this->getPoints();
  26. }
  27. public function getSrcPoints()
  28. {
  29. return array(
  30. array($this->_x , $this->_y),
  31. array($this->_x $this->_l , $this->_y),
  32. array($this->_x (1.35*$this->_l), $this->_y-(0.35*$this->_l)),
  33. array($this->_x (0.35*$this->_l), $this->_y-(0.35*$this->_l)),
  34. array($this->_x , $this->_y $this->_h),
  35. array($this->_x $this->_l , $this->_y $this->_h),
  36. array($this->_x (1.35*$this->_l), $this->_y $this->_h-(0.35*$this->_l))
  37. );
  38. }
  39. public function getPoints()
  40. {
  41. $points = array();
  42. foreach($this->_srcPoints as $key => $val)
  43. {
  44. $points[] = $val[0];
  45. $points[] = $val[1];
  46. }
  47. return $points;
  48. }
  49. public function getTopPoints()
  50. {
  51. return array_slice($this->_points, 0, 8); //顶坐标
  52. }
  53. public function getBelowPoints()
  54. {
  55. return array_merge(array_slice($this->_points, 0, 2), array_slice($this->_points, 8, 4), array_slice($this->_points, 2, 2)); //下坐标
  56. }
  57. public function getRightSidePoints()
  58. {
  59. return array_merge(array_slice($this->_points, 2, 2), array_slice($this->_points, 10, 4), array_slice($this->_points, 4, 2)); //右侧坐标
  60. }
  61. public function draw($image, $topColor, $belowColor, $sideColor, $borderColor = null, $type = LEFT)
  62. {
  63. if (is_null($borderColor))
  64. {
  65. $borderColor = 0xcccccc;
  66. }
  67. $top_rgb = $this->getRGB($topColor);
  68. $below_rgb = $this->getRGB($belowColor);
  69. $side_rgb = $this->getRGB($sideColor);
  70. $top_color = imagecolorallocate($image, $top_rgb[R], $top_rgb[G], $top_rgb[B]);
  71. $below_color = imagecolorallocate($image, $below_rgb[R], $below_rgb[G], $below_rgb[B]);
  72. $side_color = imagecolorallocate($image, $side_rgb[R], $side_rgb[G], $side_rgb[B]);
  73. imagefilledpolygon($image, $this->getTopPoints(), 4, $top_color); //画顶面
  74. imagepolygon($image, $this->getTopPoints(), 4, $borderColor); //画顶面边线
  75. imagefilledpolygon($image, $this->getBelowPoints(), 4, $below_color); //画下面
  76. imagepolygon($image, $this->getBelowPoints(), 4, $borderColor); //画下面边线
  77. if ($type == LEFT)
  78. {
  79. imagefilledpolygon($image, $this->getRightSidePoints(), 4, $side_color); //画右侧面
  80. imagepolygon($image, $this->getRightSidePoints(), 4, $borderColor); //画侧面边线
  81. }
  82. }
  83. public function getRGB($color)
  84. {
  85. $ar = array();
  86. $color = hexdec($color);
  87. $ar[R] = ($color>>16) & 0xff;
  88. $ar[G] = ($color>>8) & 0xff;
  89. $ar[B] = ($color) & 0xff;
  90. return $ar;
  91. }
  92. }
  93. class Bardate
  94. {
  95. private $_W;
  96. private $_H;
  97. private $_bgColor = "ffffff";
  98. private $_barHeights = array();
  99. private $_barTexts = array();
  100. private $_barColors = array();
  101. public $_title;
  102. public $_paddingTop = 30;
  103. public $_paddingBottom = 100;
  104. public $_paddingLeft = 45;
  105. public $_paddingRight = 2;
  106. public $_barL = 50;
  107. 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/...
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。