php 資料統計圖類執行個體代碼詳解_PHP教程

來源:互聯網
上載者:User

  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;

    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/...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.