亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 開發 > PHP > 正文

php打造智能化的柱狀圖程序,用于報表等

2024-05-04 23:36:32
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php打造智能化的柱狀圖程序,用于報表等的相關資料,需要的朋友可以參考下

php打造智能化的柱狀圖程序,用于報表等

 

 
  1. <?php  
  2. /***  
  3. * @project Bar Graph Program  
  4. * @license GPL  
  5. * @package  
  6. * @file GrapBar.php  
  7. * @date 2007-4-3  
  8. * @version 1.0  
  9. * @last modified  
  10.  
  11. * 定義 柱狀圖(柱形圖) 類  
  12.  
  13. * 注意,使用前請確保字體路徑存在并允許訪問,如果出錯,還要檢查在php.ini配置中的open_basedir項,如果沒此路徑請添加,或在程序中設置包含  
  14.  
  15. * 智能化的柱狀圖程序,用于報表等  
  16.  
  17. ***/ 
  18.  
  19. define("DEFAULT_FONT_PATH""c:/windows/fonts/simhei.ttf");  
  20. class SingleBar  
  21. {  
  22. private $_x;  
  23. private $_y;  
  24. private $_h;  
  25. public $_l = 50;  
  26. private $_w = null;  
  27. private $_srcPoints = array();  
  28. private $_points = array();  
  29.  
  30. public function __construct($x$y$h$l = 50, $w = null)  
  31. {  
  32. $this->_x = $x;  
  33. $this->_y = $y;  
  34. $this->_h = $h;  
  35. $this->_l = $l;  
  36. $this->_w = $w;  
  37. $this->_srcPoints = $this->getSrcPoints();  
  38. $this->_points = $this->getPoints();  
  39. }  
  40.  
  41. public function getSrcPoints()  
  42. {  
  43. return array(  
  44. array($this->_x , $this->_y),  
  45. array($this->_x+$this->_l , $this->_y),  
  46. array($this->_x+(1.35*$this->_l), $this->_y-(0.35*$this->_l)),  
  47. array($this->_x+(0.35*$this->_l), $this->_y-(0.35*$this->_l)),  
  48. array($this->_x , $this->_y+$this->_h),  
  49. array($this->_x+$this->_l , $this->_y+$this->_h),  
  50. array($this->_x+(1.35*$this->_l), $this->_y+$this->_h-(0.35*$this->_l))  
  51. );  
  52. }  
  53.  
  54. public function getPoints()  
  55. {  
  56. $points = array();  
  57. foreach($this->_srcPoints as $key => $val)  
  58. {  
  59. $points[] = $val[0];  
  60. $points[] = $val[1];  
  61. }  
  62. return $points;  
  63. }  
  64.  
  65. public function getTopPoints()  
  66. {  
  67. return array_slice($this->_points, 0, 8); //頂坐標  
  68. }  
  69.  
  70. public function getBelowPoints()  
  71. {  
  72. return array_merge(array_slice($this->_points, 0, 2), array_slice($this->_points, 8, 4), array_slice($this->_points, 2, 2)); //下坐標  
  73. }  
  74.  
  75. public function getRightSidePoints()  
  76. {  
  77. return array_merge(array_slice($this->_points, 2, 2), array_slice($this->_points, 10, 4), array_slice($this->_points, 4, 2)); //右側坐標  
  78. }  
  79.  
  80. public function draw($image$topColor$belowColor$sideColor$borderColor = null, $type = 'LEFT')  
  81. {  
  82. if (is_null($borderColor))  
  83. {  
  84. $borderColor = 0xcccccc;  
  85. }  
  86.  
  87. $top_rgb = $this->getRGB($topColor);  
  88. $below_rgb = $this->getRGB($belowColor);  
  89. $side_rgb = $this->getRGB($sideColor);  
  90. $top_color = imagecolorallocate($image$top_rgb['R'], $top_rgb['G'], $top_rgb['B']);  
  91. $below_color = imagecolorallocate($image$below_rgb['R'], $below_rgb['G'], $below_rgb['B']);  
  92. $side_color = imagecolorallocate($image$side_rgb['R'], $side_rgb['G'], $side_rgb['B']);  
  93.  
  94. imagefilledpolygon($image$this->getTopPoints(), 4, $top_color); //畫頂面  
  95. imagepolygon($image$this->getTopPoints(), 4, $borderColor); //畫頂面邊線  
  96.  
  97. imagefilledpolygon($image$this->getBelowPoints(), 4, $below_color); //畫下面  
  98. imagepolygon($image$this->getBelowPoints(), 4, $borderColor); //畫下面邊線  
  99.  
  100. if ($type == 'LEFT')  
  101. {  
  102. imagefilledpolygon($image$this->getRightSidePoints(), 4, $side_color); //畫右側面  
  103. imagepolygon($image$this->getRightSidePoints(), 4, $borderColor); //畫側面邊線  
  104. }  
  105. }  
  106.  
  107. public function getRGB($color)  
  108. {  
  109. $ar = array();  
  110. $color = hexdec($color);  
  111. $ar['R'] = ($color>>16) & 0xff;  
  112. $ar['G'] = ($color>>8) & 0xff;  
  113. $ar['B'] = ($color) & 0xff;  
  114. return $ar;  
  115. }  
  116. }  
  117.  
  118. class Bar  
  119. {  
  120. private $_W;  
  121. private $_H;  
  122. private $_bgColor = "ffffff";  
  123. private $_barHeights = array();  
  124. private $_barTexts = array();  
  125. private $_barColors = array();  
  126. public $_title;  
  127. public $_paddingTop = 30;  
  128. public $_paddingBottom = 100;  
  129. public $_paddingLeft = 45;  
  130. public $_paddingRight = 2;  
  131. public $_barL = 50;  
  132. public $image;  
  133.  
  134. public function __construct($imgW$imgH$barHeights$barTexts = null, $barColors = null)  
  135. {  
  136. $this->_W = $imgW;  
  137. $this->_H = $imgH;  
  138. $this->_barHeights = $barHeights;  
  139. $this->_barTexts = $barTexts;  
  140. $this->_barColors = $barColors;  
  141. $this->_paddingBottom = $this->resetPaddingBottom();  
  142. $this->_H = $this->resetHeight();  
  143. $this->image = imagecreatetruecolor($this->_W, $this->_H);  
  144. }  
  145.  
  146. public function stroke()  
  147. {  
  148. $this->drawBg();  
  149. $this->drawBars();  
  150. $this->drawTitle();  
  151. $this->drawLables();  
  152. ob_start();  
  153. //header("Content-type: image/png");  
  154. //imagepng($this->image);  
  155. header("Content-type: " . image_type_to_mime_type(IMAGETYPE_JPEG));  
  156. imagejpeg($this->image);  
  157. imagedestroy($this->image);  
  158. }  
  159.  
  160. public function drawBg()  
  161. {  
  162. $img_w = $this->_W;  
  163. $img_h = $this->_H;  
  164. $paddingTop = $this->_paddingTop;  
  165. $paddingBottom = $this->_paddingBottom;  
  166. $paddingLeft = $this->_paddingLeft;  
  167. $paddingRight = $this->_paddingRight;  
  168. $rgb = $this->getRGB($this->_bgColor);  
  169. $bg = imagecolorallocate($this->image,$rgb['R'], $rgb['G'], $rgb['B']);  
  170. imagefilledrectangle($this->image, 0, 0, $img_w$img_h$bg);  
  171. $side_bg = imagecolorallocatealpha($this->image, 220, 220, 220, 75);  
  172. $side_bg2 = imagecolorallocate($this->image, 220, 220, 220);  
  173. $border_color = imagecolorallocate($this->image, 190, 190, 190);  
  174. $line_color = imagecolorallocate($this->image, 236, 236, 236);  
  175. $dial_color = imagecolorallocate($this->image, 131, 131, 131);  
  176.  
  177. $x1 = $paddingLeft;  
  178. $y1 = $paddingTop;  
  179. $x2 = $img_w - $paddingRight;  
  180. $y2 = $img_h - $paddingBottom;  
  181. imagerectangle($this->image, $x1$y1$x2$y2$border_color);  
  182. imagefilledpolygon($this->image, array($x1-5,$y1+10, $x1-5,$y2+10, $x1,$y2$x1,$y1), 4, $side_bg);  
  183. imagepolygon($this->image, array($x1-5,$y1+10, $x1-5,$y2+10, $x1,$y2$x1,$y1), 4, $border_color);  
  184. imagefilledpolygon($this->image, array($x1-5,$y2+10, $x2-5,$y2+10, $x2,$y2$x1,$y2), 4, $side_bg);  
  185. imagepolygon($this->image, array($x1-5,$y2+10, $x2-5,$y2+10, $x2,$y2$x1,$y2), 4, $border_color);  
  186. imageline($this->image, $x1$y2$x2$y2$side_bg2);  
  187.  
  188. $total_h = $img_h - $paddingTop - $paddingBottom;  
  189. $every_h = $total_h/11;  
  190. for($i=1; $i<=10; $i++)  
  191. {  
  192. imageline($this->image, $x1$y1+($every_h*$i), $x2$y1+($every_h*$i), $line_color); //畫網線  
  193. }  
  194.  
  195. $max_h = max($this->_barHeights);  
  196. for($i=1; $i<=10; $i++)  
  197. {  
  198. $value = $max_h - (($max_h/10)*($i-1));  
  199. $value = strval($value);  
  200. $str_w = strlen($value)*5;  
  201. imageline($this->image, $x1-5-3, $y1+10+($every_h*$i), $x1-3+1, $y1+10+($every_h*$i), $dial_color); //畫刻度線  
  202. imagestring($this->image, 3, $x1-5-3-$str_w-1, $y1+10+($every_h*$i)-5, $value, 0x000000);  
  203. }  
  204. }  
  205.  
  206.  
  207. public function drawBars()  
  208. {  
  209. $counts = count($this->_barHeights);  
  210. if (emptyempty($this->_barColors))  
  211. {  
  212. $color = $this->setColor();  
  213. $this->_barColors = array_slice($color, 0, $counts);  
  214. //shuffle($this->_barColors);  
  215. }  
  216. $every_w = ($this->_W - $this->_paddingLeft - $this->_paddingRight)/$counts//每一段寬  
  217. $barL = $every_w;  
  218. $barL = ($barL > $this->_barL*1.35+6) ? $this->_barL : $barL/1.35 - 6;  
  219. $max_h = max($this->_barHeights);  
  220. $ruler_h = $this->_H - $this->_paddingTop - $this->_paddingBottom; //標尺總高度  
  221. $stander_h = $ruler_h - ($ruler_h/11); //標尺10等分的高度  
  222. $i = 0;  
  223. foreach ($this->_barHeights as $val)  
  224. {  
  225. $h = ($stander_h/$max_h)*$val;  
  226. $x = $this->_paddingLeft + ($every_w*$i) + (($every_w - ($barL*1.35))/2);;  
  227. $y = $this->_H - $this->_paddingBottom + 10 - $h;  
  228. //$t_color = $this->_barColors[$i];  
  229. $b_color = $this->_barColors[$i];  
  230. //$s_color = $this->_barColors[$i];  
  231.  
  232.  
  233. $rgb = $this->getRGB($this->_barColors[$i]);  
  234. $R = $rgb['R'] * 0.7;  
  235. $G = $rgb['G'] * 0.7;  
  236. $B = $rgb['B'] * 0.7;  
  237.  
  238. $c1 = $R > 0 ? dechex($R) : '00';  
  239. $c2 = $G > 0 ? dechex($G) : '00';  
  240. $c3 = $B > 0 ? dechex($B) : '00';  
  241.  
  242. $t_color = $b_color;  
  243. $s_color = $c1$c2 . $c3;  
  244.  
  245. $SingleBar = new SingleBar($x$y$h$barL);  
  246. $SingleBar->draw($this->image, $t_color$b_color$s_color);  
  247. $i++;  
  248. }  
  249. }  
  250.  
  251. public function drawTitle()  
  252. {  
  253. if (emptyempty($this->_title))  
  254. {  
  255. return;  
  256. }  
  257. $font = 5;  
  258. $font_w = imagefontwidth($font);  
  259. $len = strlen($this->_title);  
  260. $x = ($this->_W + $this->_paddingLeft - $this->_paddingRight)/2;  
  261. $x -= ($len*$font_w)/2;  
  262. $y = ($this->_paddingTop - $font_w)/2 + 12;  
  263. //imagestring($this->image, $font, $x, $y, $title, 0x000000);  
  264. imagettftext($this->image, 12, 0, $x$y, 0x000000, DEFAULT_FONT_PATH, $this->_title);  
  265. }  
  266.  
  267. public function drawLables()  
  268. {  
  269. $x1 = $this->_paddingLeft - 5;  
  270. $y1 = $this->_H - $this->_paddingBottom + 20;  
  271. $x2 = $this->_W - $this->_paddingRight;  
  272. $y2 = $this->_H - 10;  
  273. //imagefilledrectangle($this->image, $x1, $y1, $x2, $y2, 0xffffff);  
  274. imagerectangle($this->image, $x1$y1$x2$y2, 0x000000);  
  275. $space = 5;  
  276. $x = $x1 + 3;  
  277. $y = $y1 + 3;  
  278. foreach ($this->_barTexts as $key => $val)  
  279. {  
  280. $color = $this->_barColors[$key];  
  281. $rgb = $this->getRGB($color);  
  282. $bg = imagecolorallocate($this->image,$rgb['R'], $rgb['G'], $rgb['B']);  
  283. imagefilledrectangle($this->image, $x$y$x+12, $y+12, $bg); //繪12*12的矩形  
  284. imagerectangle($this->image, $x$y$x+12, $y+12, 0x000000); //繪12*12的矩形框  
  285. imagettftext($this->image, 12, 0, $x+12+3, $y+12, 0x000000, DEFAULT_FONT_PATH, $val);  
  286. $x += 12 + $space + (strlen($val)*8) + $space;  
  287. if ($x + (strlen($val)*8) >= $this->_W - $this->_paddingLeft - $this->_paddingRight)  
  288. {  
  289. $x = $x1 + 3;  
  290. $y = $y + 12 + 3;  
  291. }  
  292. }  
  293. }  
  294.  
  295. public function resetPaddingBottom()  
  296. {  
  297. $ruler_w = $this->_W - $this->_paddingLeft - $this->_paddingRight;  
  298. $label_w = $this->getLableTotalWidth();  
  299. $lines = ceil($label_w / $ruler_w);  
  300. $h = 12 * $lines + (3 * ($lines + 1)) + 30;  
  301. return $h;  
  302. }  
  303.  
  304. public function resetHeight()  
  305. {  
  306. $padding_bottom = $this->resetPaddingBottom();  
  307. if ($this->_H - $padding_bottom < 222)  
  308. {  
  309. return 222 + $padding_bottom;  
  310. }  
  311. return $this->_H;  
  312. }  
  313.  
  314.  
  315. public function getLableTotalWidth()  
  316. {  
  317. $counts = count($this->_barTexts);  
  318. $space = 5;  
  319. $total_len = 0;  
  320. foreach ($this->_barTexts as $val)  
  321. {  
  322. $total_len += strlen($val);  
  323. }  
  324.  
  325. $tx_w = ($total_len * 9) + ((12 + 3 + $space) * $counts);  
  326. return $tx_w;  
  327. }  
  328.  
  329. public function setBg($color)  
  330. {  
  331. $this->_bgColor = $color;  
  332. }  
  333.  
  334. public function setTitle($title)  
  335. {  
  336. $this->_title = $title;  
  337. }  
  338.  
  339. public function setColor()  
  340. {  
  341. $ar = array('ff''00''33''66''99''cc');  
  342. $color = array();  
  343. for ($i=0; $i<6; $i++)  
  344. {  
  345. for ($j=0; $j<6; $j++)  
  346. {  
  347. for($k=0; $k<6; $k++)  
  348. {  
  349. $color[] = $ar[$i] . $ar[$j] . $ar[$k];  
  350. }  
  351. }  
  352. }  
  353.  
  354. $color2 = array();  
  355. for ($i=1; $i<216; $i += 4)  
  356. {  
  357. $color2[] = $color[$i];  
  358. }  
  359.  
  360. return $color2;  
  361. }  
  362.  
  363. public function getRGB($color)  
  364. {  
  365. $ar = array();  
  366. $color = hexdec($color);  
  367. $ar['R'] = ($color>>16) & 0xff;  
  368. $ar['G'] = ($color>>8) & 0xff;  
  369. $ar['B'] = ($color) & 0xff;  
  370. return $ar;  
  371. }  
  372. }  
  373.  
  374. /***/ 
  375. $bar = new Bar(500, 300, array(600, 300, 30, 500, 400, 250, 350, 360), array('AAAAA''BBBBB''CCCCC''DDDDD''EEEEEE''FFFFFF''GGGGGGG''HHHHHHHHH'));  
  376. $bar->setTitle('打造完美柱狀圖!');  
  377. $bar->stroke();  
  378. /***/ 
  379. ?> 

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲精品视频网上网址在线观看| 国产成人在线一区| 久久久亚洲精品视频| 亚洲精品一区二区在线| 国产午夜精品理论片a级探花| 久久久久久久久爱| 欧洲精品在线视频| 亚洲人成电影在线| 国产视频欧美视频| 国产精品第七影院| 日韩成人网免费视频| 精品香蕉在线观看视频一| 国产精品一区二区三区在线播放| 亚洲视屏在线播放| 国产精品第七影院| 国产精品亚洲网站| 中日韩美女免费视频网站在线观看| 亚洲综合在线小说| 日本三级韩国三级久久| 91麻豆国产语对白在线观看| 精品国产福利视频| 日韩欧美在线观看| 国产精品日韩欧美大师| 国产精品成人aaaaa网站| 久久久精品一区二区| 91精品国产高清自在线| 亚洲另类图片色| 最近2019好看的中文字幕免费| 免费99精品国产自在在线| 国产免费成人av| 精品二区三区线观看| 欧美精品电影免费在线观看| 亚洲欧洲日产国码av系列天堂| 日本成人在线视频网址| 国产日产欧美精品| 国产精品日韩在线一区| 97国产在线观看| 欧美老女人性生活| 日韩中文字幕精品视频| 性欧美长视频免费观看不卡| 亚洲欧美另类中文字幕| 成人伊人精品色xxxx视频| 国产成人综合久久| 久久乐国产精品| 亚洲第一视频在线观看| 欧美在线精品免播放器视频| 色偷偷噜噜噜亚洲男人的天堂| 欧美精品在线观看91| 热久久视久久精品18亚洲精品| 国产成+人+综合+亚洲欧洲| 一区二区三区天堂av| 555www成人网| 日韩视频免费看| 欧美性受xxxx白人性爽| 欧美精品久久久久久久免费观看| 日韩成人在线免费观看| 久久噜噜噜精品国产亚洲综合| 国产精品999| 精品中文字幕在线观看| 午夜精品三级视频福利| 久久久久久久久综合| 91久久精品国产| 国模极品一区二区三区| 精品无人区太爽高潮在线播放| 欧美精品生活片| 国产精品第100页| 日韩的一区二区| 亚洲精品资源美女情侣酒店| 久久久免费在线观看| 国产精品偷伦视频免费观看国产| 久久免费国产精品1| 国产精品99久久久久久白浆小说| 97香蕉久久超级碰碰高清版| 狠狠操狠狠色综合网| 国产免费一区二区三区在线观看| 国产一区二区三区直播精品电影| 国产成人精品午夜| 国产一区二区三区欧美| 国产精品免费电影| 日韩免费av在线| 精品福利视频导航| 91成人精品网站| 久久久久久久色| 国产成人91久久精品| 亚洲国模精品一区| 国产噜噜噜噜久久久久久久久| 欧美视频一二三| 国产日韩亚洲欧美| 国产精品爽爽爽| 久久婷婷国产麻豆91天堂| 欧美高清视频免费观看| 韩国一区二区电影| 亚洲天堂精品在线| 亚洲精品影视在线观看| 欧美午夜激情在线| 亚洲精品久久久久久久久| 亚洲精品一区二区三区婷婷月| 欧美午夜精品伦理| 911国产网站尤物在线观看| 亚洲欧美日韩直播| 亚洲r级在线观看| 色妞久久福利网| 亚洲免费视频网站| 亚洲人成在线免费观看| 国产精品第10页| 亚洲毛片在线观看.| 欧美成人免费全部| 欧美壮男野外gaytube| 欧美激情奇米色| 久久久噜噜噜久噜久久| 成人国产精品一区| 亚洲最新av在线网站| 亚洲精品久久视频| 欧美激情精品久久久| xvideos成人免费中文版| 成人综合国产精品| 国产一区二区久久精品| 91理论片午午论夜理片久久| 久久国产精品首页| 中文字幕在线观看亚洲| 精品国产自在精品国产浪潮| 高清一区二区三区日本久| 久久久成人av| 日韩精品欧美激情| 91久久久久久久久久久| 91色琪琪电影亚洲精品久久| 国产精品视频专区| 在线日韩中文字幕| 欧美日韩一区二区免费在线观看| 欧美不卡视频一区发布| 精品夜色国产国偷在线| 国产成人综合久久| 国产精品美女免费视频| 亚洲福利视频免费观看| 色综合男人天堂| 国产福利成人在线| 久久男人资源视频| 亚洲一区二区三区777| 精品美女国产在线| 欧美性猛交xxxx免费看漫画| 精品一区二区三区三区| 欧美久久精品一级黑人c片| 国产精品免费一区| 国产精品自拍偷拍| 欧美精品一本久久男人的天堂| 日本久久久久久久久久久| 午夜精品福利电影| 国产一区二区日韩精品欧美精品| 国产丝袜高跟一区| 国产精品高潮呻吟久久av黑人| 琪琪第一精品导航| 久久99热这里只有精品国产| 国产色视频一区| 亚洲精品大尺度| 国产精品私拍pans大尺度在线| 亚洲国产成人精品久久久国产成人一区| 88国产精品欧美一区二区三区| 久久理论片午夜琪琪电影网| 色先锋资源久久综合5566| 欧美日韩美女在线| 亚洲欧美日韩国产中文专区| 欧美电影免费在线观看| 国产成人福利网站| 久久久久北条麻妃免费看|