PHP Data Chart Class instance code detailed _php tutorial

Source: Internet
Author: User

  1. /***
  2. * Time 2010-8-9
  3. * www.ite5e.com
  4. * Note: If you have any questions, you can reply.
  5. * Test code is called at the bottom of the program.
  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 = a, $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); Top coordinates
  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)); Bottom coordinate
  56. }
  57. Public Function getrightsidepoints ()
  58. {
  59. Return Array_merge (Array_slice ($this->_points, 2, 2), Array_slice ($this->_points, ten, 4), Array_slice ($this- >_points, 4, 2)); Right coordinate
  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); Draw the top face
  74. Imagepolygon ($image, $this->gettoppoints (), 4, $borderColor); Draw Top Edge
  75. Imagefilledpolygon ($image, $this->getbelowpoints (), 4, $below _color); Draw below
  76. Imagepolygon ($image, $this->getbelowpoints (), 4, $borderColor); Draw the bottom edge
  77. if ($type = = left)
  78. {
  79. Imagefilledpolygon ($image, $this->getrightsidepoints (), 4, $side _color); Draw right Side
  80. Imagepolygon ($image, $this->getrightsidepoints (), 4, $borderColor); Draw side edges
  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.html www.bkjia.com true http://www.bkjia.com/PHPjc/486183.html techarticle PHP/*** * Time 2010-8-9 * www.ite5e.com * NOTE: If there is any problem can reply. * Test code is called at the bottom of the program. /define ("Default_font_path", "c:/windows/fonts/...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.