백엔드 개발 PHP 튜토리얼 PHP는 히스토그램을 그립니다

PHP는 히스토그램을 그립니다

Jul 25, 2016 am 08:43 AM

  1. /***
  2. * @project 막대 그래프 프로그램
  3. * @license GPL
  4. * @package
  5. * @file GrapBar.php
  6. * @date 2007-4-3
  7. * @version 1.0
  8. * @last Modified
  9. * 히스토그램(컬럼차트) 클래스 정의
  10. *
  11. * 참고로 사용 전 폰트 경로가 존재하고 접근을 허용하는지 확인하고, error php.ini 구성의 open_basedir 항목에 해당 경로가 없으면 추가하거나 프로그램에 포함하도록 설정하세요.
  12. *
  13. * 보고서 등에 사용되는 지능형 히스토그램 프로그램
  14. *
  15. * **/
  16. 정의("DEFAULT_FONT_PATH", "c:/windows/fonts/simhei.ttf ");
  17. class SingleBar
  18. {
  19. private $_x;
  20. 비공개 $_y;
  21. 비공개 $_h;
  22. 공개 $_l = 50;
  23. 비공개 $_w = null;
  24. 비공개 $_srcPoints = 배열();
  25. 비공개 $_points = array();
  26. 공개 함수 __construct($x, $y, $h, $l = 50, $w = null)
  27. {
  28. $this->_x = $x;
  29. $this->_y = $y;
  30. $this->_h = $h;
  31. $this->_l = $l;
  32. $this->_w = $w;
  33. $this->_srcPoints = $this->getSrcPoints();
  34. $this->_points = $this->getPoints();
  35. }
  36. 공용 함수 getSrcPoints()
  37. {
  38. return array(
  39. array($this->_x , $this->_y),
  40. array( $this->_x $this->_l , $this->_y),
  41. array($this->_x (1.35*$this->_l), $this->_y- (0.35*$this->_l)),
  42. array($this->_x (0.35*$this->_l), $this->_y-(0.35*$this->_l )),
  43. 배열($this->_x , $this->_y $this->_h),
  44. 배열($this->_x $this->_l , $this- >_y $this->_h),
  45. array($this->_x (1.35*$this->_l), $this->_y $this->_h-(0.35*$ this->_l))
  46. );
  47. }
  48. 공용 함수 getPoints()
  49. {
  50. $points = array();
  51. foreach($this->_srcPoints as $key => $val)
  52. {
  53. $points[] = $val[0];
  54. $포인트[] = $val[1];
  55. }
  56. $포인트를 반환합니다.
  57. }
  58. 공용 함수 getTopPoints()
  59. {
  60. return array_slice($this->_points, 0, 8); //顶坐标
  61. }
  62. public function getBelowPoints()
  63. {
  64. return array_merge(array_slice($this->_points, 0, 2), array_slice($this-> _points, 8, 4), array_slice($this->_points, 2, 2)); //下坐标
  65. }
  66. public function getRightSidePoints()
  67. {
  68. return array_merge(array_slice($this->_points, 2, 2), array_slice($this-> _points, 10, 4), array_slice($this->_points, 4, 2)); //右侧坐标
  69. }
  70. 공개 함수 draw($image, $topColor, $belowColor, $sideColor, $borderColor = null, $type = 'LEFT')
  71. {
  72. if (is_null($borderColor))
  73. {
  74. $borderColor = 0xcccccc;
  75. }
  76. $top_rgb = $this->getRGB($topColor);
  77. $below_rgb = $this->getRGB($belowColor);
  78. $side_rgb = $this->getRGB($sideColor);
  79. $top_color = imagecolorallocate($image, $top_rgb['R'], $top_rgb['G'], $top_rgb['B']);
  80. $below_color = imagecolorallocate($image, $below_rgb['R'], $below_rgb['G'], $below_rgb['B']);
  81. $side_color = imagecolorallocate($image, $side_rgb['R'], $side_rgb['G'], $side_rgb['B']);
  82. imagefilledpolygon($image, $this->getTopPoints(), 4, $top_color); //페이지 화면
  83. imagepolygon($image, $this->getTopPoints(), 4, $borderColor); //화면면边线
  84. imagefilledpolygon($image, $this->getBelowPoints(), 4, $below_color); //아래쪽
  85. imagepolygon($image, $this->getBelowPoints(), 4, $borderColor); //아래쪽 화면
  86. if ($type == 'LEFT')
  87. {
  88. imagefilledpolygon($image, $this->getRightSidePoints(), 4, $side_color); //画右侧면
  89. imagepolygon($image, $this->getRightSidePoints(), 4, $borderColor); //画侧면边线
  90. }
  91. }
  92. 공용 함수 getRGB($color)
  93. {
  94. $ar = array();
  95. $color = hexdec($color);
  96. $ar['R'] = ($color>>16) & 0xff;
  97. $ar['G'] = ($color>>8) & 0xff;
  98. $ar['B'] = ($color) & 0xff;
  99. $ar 반환;
  100. }
  101. }
  102. 클래스 바
  103. {
  104. private $_W;
  105. 비공개 $_H;
  106. 비공개 $_bgColor = "ffffff";
  107. 비공개 $_barHeights = array();
  108. 비공개 $_barTexts = array();
  109. 비공개 $_barColors = array();
  110. 공개 $_title;
  111. 공개 $_paddingTop = 30;
  112. 공개 $_paddingBottom = 100;
  113. 공개 $_paddingLeft = 45;
  114. 공개 $_paddingRight = 2;
  115. 공개 $_barL = 50;
  116. 공개 $이미지;
  117. 공개 함수 __construct($imgW, $imgH, $barHeights, $barTexts = null, $barColors = null)
  118. {
  119. $this->_W = $imgW;
  120. $this->_H = $imgH;
  121. $this->_barHeights = $barHeights;
  122. $this->_barTexts = $barTexts;
  123. $this->_barColors = $barColors;
  124. $this->_paddingBottom = $this->resetPaddingBottom();
  125. $this->_H = $this->resetHeight();
  126. $this->image = imagecreatetruecolor($this->_W, $this->_H);
  127. }
  128. 공용 함수 스트로크()
  129. {
  130. $this->drawBg();
  131. $this->drawBars();
  132. $this->drawTitle();
  133. $this->drawLables();
  134. ob_start();
  135. //header("콘텐츠 유형: 이미지/png");
  136. //imagepng($this->image);
  137. header("콘텐츠 유형: " . image_type_to_mime_type(IMAGETYPE_JPEG));
  138. imagejpeg($this->image);
  139. imagedestroy($this->image);
  140. }
  141. 공개 함수 drawBg()
  142. {
  143. $img_w = ​​$this->_W;
  144. $img_h = $this->_H;
  145. $paddingTop = $this->_paddingTop;
  146. $paddingBottom = $this->_paddingBottom;
  147. $paddingLeft = $this->_paddingLeft;
  148. $paddingRight = $this->_paddingRight;
  149. $rgb = $this->getRGB($this->_bgColor);
  150. $bg = imagecolorallocate($this->image,$rgb['R'], $rgb['G'], $rgb['B']);
  151. imagefilled직사각형($this->image, 0, 0, $img_w, $img_h, $bg);
  152. $side_bg = imagecolorallocatealpha($this->image, 220, 220, 220, 75);
  153. $side_bg2 = imagecolorallocate($this->image, 220, 220, 220);
  154. $border_color = imagecolorallocate($this->image, 190, 190, 190);
  155. $line_color = imagecolorallocate($this->image, 236, 236, 236);
  156. $dial_color = imagecolorallocate($this->image, 131, 131, 131);
  157. $x1 = $paddingLeft;
  158. $y1 = $paddingTop;
  159. $x2 = $img_w - $paddingRight;
  160. $y2 = $img_h - $paddingBottom;
  161. imageRectangle($this->image, $x1, $y1, $x2, $y2, $border_color);
  162. imagefilledpolygon($this->image, array($x1-5,$y1 10, $x1-5,$y2 10, $x1,$y2, $x1,$y1), 4, $side_bg) ;
  163. imagepolygon($this->image, array($x1-5,$y1 10, $x1-5,$y2 10, $x1,$y2, $x1,$y1), 4, $border_color) ;
  164. imagefilledpolygon($this->image, array($x1-5,$y2 10, $x2-5,$y2 10, $x2,$y2, $x1,$y2), 4, $side_bg) ;
  165. imagepolygon($this->image, array($x1-5,$y2 10, $x2-5,$y2 10, $x2,$y2, $x1,$y2), 4, $border_color) ;
  166. imageline($this->image, $x1, $y2, $x2, $y2, $side_bg2);
  167. $total_h = $img_h - $paddingTop - $paddingBottom;
  168. $every_h = $total_h/11;
  169. for($i=1; $i<=10; $i )
  170. {
  171. imageline($this->image, $x1, $y1 ($every_h*$i), $x2 , $y1 ($every_h*$i), $line_color); //画网线
  172. }
  173. $max_h = max($this->_barHeights);
  174. for($i=1; $i<=10; $i )
  175. {
  176. $value = $max_h - (($max_h/10)*($i-1));
  177. $value = strval($value);
  178. $str_w = strlen($value)*5;
  179. imageline($this->image, $x1-5-3, $y1 10 ($every_h*$i), $x1-3 1, $y1 10 ($every_h*$i), $dial_color) ; //확률도线
  180. imagestring($this->image, 3, $x1-5-3-$str_w-1, $y1 10 ($every_h*$i)-5, $value, 0x000000);
  181. }
  182. }
  183. 공개 함수 drawBars()
  184. {
  185. $counts = count($this->_barHeights);
  186. if (empty($this->_barColors))
  187. {
  188. $color = $this->setColor();
  189. $this->_barColors = array_slice($color, 0, $counts);
  190. //shuffle($this->_barColors);
  191. }
  192. $every_w = ($this->_W - $this->_paddingLeft - $this->_paddingRight)/$counts; //每一段宽
  193. $barL = $every_w;
  194. $barL = ($barL > $this->_barL*1.35 6) ? $this->_barL : $barL/1.35 - 6;
  195. $max_h = max($this->_barHeights);
  196. $ruler_h = $this->_H - $this->_paddingTop - $this->_paddingBottom; //标尺总고도
  197. $stander_h = $ruler_h - ($ruler_h/11); //10분할 높이
  198. $i = 0;
  199. foreach ($this->_barHeights as $val)
  200. {
  201. $h = ($stander_h/$max_h)*$val;
  202. $x = $this->_paddingLeft ($every_w*$i) (($every_w - ($barL*1.35))/2);;
  203. $y = $this->_H - $this->_padding하단 10 - $h;
  204. //$t_color = $this->_barColors[$i];
  205. $b_color = $this->_barColors[$i];
  206. //$s_color = $this->_barColors[$i];
  207. $rgb = $this->getRGB($this->_barColors[$i]);
  208. $R ​​= $rgb['R'] * 0.7;
  209. $G = $rgb['G'] * 0.7;
  210. $B = $rgb['B'] * 0.7;
  211. $c1 = $R > 0? 데첵스($R) : '00';
  212. $c2 = $G > 0? 데첵($G) : '00';
  213. $c3 = $B > 0? 데첵($B) : '00';
  214. $t_color = $b_color;
  215. $s_color = $c1. $c2 . $c3;
  216. $SingleBar = new SingleBar($x, $y, $h, $barL);
  217. $SingleBar->draw($this->image, $t_color, $b_color, $s_color);
  218. $i ;
  219. }
  220. }
  221. 공용 함수 drawTitle()
  222. {
  223. if (empty($this->_title))
  224. {
  225. return;
  226. }
  227. $font = 5;
  228. $font_w = 이미지폰트폭($font);
  229. $len = strlen($this->_title);
  230. $x = ($this->_W $this->_paddingLeft - $this->_paddingRight)/2;
  231. $x -= ($len*$font_w)/2;
  232. $y = ($this->_paddingTop - $font_w)/2 12;
  233. //imagestring($this->image, $font, $x, $y, $title, 0x000000);
  234. imagettftext($this->image, 12, 0, $x, $y, 0x000000, DEFAULT_FONT_PATH, $this->_title);
  235. }
  236. 공개 함수 drawLables()
  237. {
  238. $x1 = $this->_paddingLeft - 5;
  239. $y1 = $this->_H - $this->_paddingBottom 20;
  240. $x2 = $this->_W - $this->_paddingRight;
  241. $y2 = $this->_H - 10;
  242. //imagefilled직사각형($this->image, $x1, $y1, $x2, $y2, 0xffffff);
  243. imageRectangle($this->image, $x1, $y1, $x2, $y2, 0x000000);
  244. $space = 5;
  245. $x = $x1 3;
  246. $y = $y1 3;
  247. foreach ($this->_barTexts as $key => $val)
  248. {
  249. $color = $this->_barColors[$key];
  250. $rgb = $this->getRGB($color);
  251. $bg = imagecolorallocate($this->image,$rgb['R'], $rgb['G'], $rgb['B']);
  252. imagefilled직사각형($this->image, $x, $y, $x 12, $y 12, $bg); //绘12*12형
  253. imageRectangle($this->image, $x, $y, $x 12, $y 12, 0x000000); //형 12*12개의 형식
  254. imagettftext($this->image, 12, 0, $x 12 3, $y 12, 0x000000, DEFAULT_FONT_PATH, $val);
  255. $x = 12 $space (strlen($val)*8) $space;
  256. if ($x (strlen($val)*8) >= $this->_W - $this->_paddingLeft - $this->_paddingRight)
  257. {
  258. $x = $x1 3;
  259. $y = $y 12 3;
  260. }
  261. }
  262. }
  263. 공개 함수 ResetPaddingBottom()
  264. {
  265. $ruler_w = $this->_W - $this->_paddingLeft - $this- >_paddingRight;
  266. $label_w = $this->getLableTotalWidth();
  267. $lines = ceil($label_w / $ruler_w);
  268. $h = 12 * $lines (3 * ($lines 1)) 30;
  269. $h를 반환합니다.
  270. }
  271. 공개 함수 ResetHeight()
  272. {
  273. $padding_bottom = $this->resetPaddingBottom();
  274. if ($this->_H - $padding_bottom < 222)
  275. {
  276. return 222 $padding_bottom;
  277. }
  278. return $this->_H;
  279. }
  280. 공개 함수 getLableTotalWidth()
  281. {
  282. $counts = count($this->_barTexts);
  283. $space = 5;
  284. $total_len = 0;
  285. foreach ($this->_barTexts as $val)
  286. {
  287. $total_len = strlen($val);
  288. }
  289. $tx_w = ($total_len * 9) ((12 3 $space) * $counts);
  290. $tx_w 반환;
  291. }
  292. 공개 함수 setBg($color)
  293. {
  294. $this->_bgColor = $color;
  295. }
  296. 공개 함수 setTitle($title)
  297. {
  298. $this->_title = $title;
  299. }
  300. 공용 함수 setColor()
  301. {
  302. $ar = array('ff', '00', '33', '66', '99', 'cc' );
  303. $color = 배열();
  304. for ($i=0; $i {
  305. for ($j=0; $j {
  306. for($ k=0; $k<6; $k )
  307. {
  308. $color[] = $ar[$i] . $ar[$j] . $ar[$k];
  309. }
  310. }
  311. }
  312. $color2 = array();
  313. for ($i=1; $i<216; $i = 4)
  314. {
  315. $color2[] = $color[$i];
  316. }
  317. return $color2;
  318. }
  319. 공개 함수 getRGB($color)
  320. {
  321. $ar = array();
  322. $color = hexdec($color);
  323. $ar['R'] = ($color>>16) & 0xff;
  324. $ar['G'] = ($color>>8) & 0xff;
  325. $ar['B'] = ($color) & 0xff;
  326. $ar 반환;
  327. }
  328. }
  329. /***/
  330. $bar = new Bar(500, 300, array(600, 300, 30, 500, 400, 250, 350, 360) , array('AAAAA', 'BBBBB', 'CCCCC', 'DDDDD', 'EEEEEE', 'FFFFFF', 'GGGGGGG', 'HHHHHHHHH'));
  331. $bar->setTitle('打造完美柱状图!');
  332. $bar->스트로크();
  333. /***/
  334. ?>
제제대码



柱状图, php


본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) 11 최고의 PHP URL 쇼트너 스크립트 (무료 및 프리미엄) Mar 03, 2025 am 10:49 AM

종종 키워드와 추적 매개 변수로 혼란스러워하는 긴 URL은 방문자를 방해 할 수 있습니다. URL 단축 스크립트는 솔루션을 제공하여 소셜 미디어 및 기타 플랫폼에 이상적인 간결한 링크를 만듭니다. 이 스크립트는 개별 웹 사이트 a에 유용합니다

Instagram API 소개 Instagram API 소개 Mar 02, 2025 am 09:32 AM

Instagram은 2012 년 Facebook에서 유명한 인수에 이어 타사 사용을 위해 두 개의 API 세트를 채택했습니다. Instagram Graph API 및 Instagram Basic Display API입니다. 개발자는

Laravel의 플래시 세션 데이터로 작업합니다 Laravel의 플래시 세션 데이터로 작업합니다 Mar 12, 2025 pm 05:08 PM

Laravel은 직관적 인 플래시 방법을 사용하여 임시 세션 데이터 처리를 단순화합니다. 응용 프로그램에 간단한 메시지, 경고 또는 알림을 표시하는 데 적합합니다. 데이터는 기본적으로 후속 요청에만 지속됩니다. $ 요청-

Laravel Back End : Part 2, React가있는 React 앱 구축 Laravel Back End : Part 2, React가있는 React 앱 구축 Mar 04, 2025 am 09:33 AM

이것은 Laravel 백엔드가있는 React Application을 구축하는 데있어 시리즈의 두 번째이자 마지막 부분입니다. 이 시리즈의 첫 번째 부분에서는 기본 제품 목록 응용 프로그램을 위해 Laravel을 사용하여 편안한 API를 만들었습니다. 이 튜토리얼에서는 Dev가 될 것입니다

Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Laravel 테스트에서 단순화 된 HTTP 응답 조롱 Mar 12, 2025 pm 05:09 PM

Laravel은 간결한 HTTP 응답 시뮬레이션 구문을 제공하여 HTTP 상호 작용 테스트를 단순화합니다. 이 접근법은 테스트 시뮬레이션을보다 직관적으로 만들면서 코드 중복성을 크게 줄입니다. 기본 구현은 다양한 응답 유형 단축키를 제공합니다. Illuminate \ support \ Facades \ http를 사용하십시오. http :: 가짜 ([ 'google.com'=> ​​'Hello World', 'github.com'=> ​​[ 'foo'=> 'bar'], 'forge.laravel.com'=>

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법 Mar 14, 2025 am 11:42 AM

PHP 클라이언트 URL (CURL) 확장자는 개발자를위한 강력한 도구이며 원격 서버 및 REST API와의 원활한 상호 작용을 가능하게합니다. PHP CURL은 존경받는 다중 프로모토콜 파일 전송 라이브러리 인 Libcurl을 활용하여 효율적인 execu를 용이하게합니다.

Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Codecanyon에서 12 개의 최고의 PHP 채팅 스크립트 Mar 13, 2025 pm 12:08 PM

고객의 가장 긴급한 문제에 실시간 인스턴트 솔루션을 제공하고 싶습니까? 라이브 채팅을 통해 고객과 실시간 대화를 나누고 문제를 즉시 해결할 수 있습니다. 그것은 당신이 당신의 관습에 더 빠른 서비스를 제공 할 수 있도록합니다.

2025 PHP 상황 조사 발표 2025 PHP 상황 조사 발표 Mar 03, 2025 pm 04:20 PM

2025 PHP Landscape Survey는 현재 PHP 개발 동향을 조사합니다. 개발자와 비즈니스에 대한 통찰력을 제공하는 프레임 워크 사용, 배포 방법 및 과제를 탐색합니다. 이 조사는 현대 PHP Versio의 성장을 예상합니다

See all articles