Php Data Statistics graph instance code details _ PHP Tutorial

Source: Internet
Author: User
Php Data Statistics graph instance code details .? Php *** time * www.ite5e.com * Note: If you have any questions, please reply. * The program has the call test code at the bottom. * ** Define (DEFAULT_FONT_PATH, c: windowsfonts

  1. /***
  2. * Time
  3. * Www.ite5e.com
  4. * Note: If you have any questions, you can reply.
  5. * The program has the call test code at the bottom.
  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); // Top coordinate
  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); // coordinates
  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); // coordinates on the right
  60. }
  61. Public function draw ($ image, $ topColor, $ belowColor, $ sideColor, $ borderColor = null, $ type = LEFT)
  62. {
  63. If (is_null ($ borderColor ))
  64. {
  65. $ BorderColor = 0 xcccccc;
  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 surface
  74. Imagepolygon ($ image, $ this-> getTopPoints (), 4, $ borderColor); // draw the top edge
  75. Imagefilledpolygon ($ image, $ this-> getBelowPoints (), 4, $ below_color); // draw the following
  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 the 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.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486183.htmlTechArticle? Php/*** time (* www.ite5e.com *) Note: reply if you have any questions. * The program has the call test code at the bottom. * **/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.