1. <?php
  2.   // 출처 및 인용 : http://www.php100.com/html/php/lei/2013/0905/4993.html
  3.   // GET 파라미터로 가로 막대 그래프 적용 위한 설정
  4.   if(ctype_print($_GET["h_bar"])) $h_bar = explode(",", $_GET['h_bar']);
  5.   else $h_bar = array(20, 10, 50, 40, 33, 26, 3);
  6.   
  7.   //막대 총 수
  8.   $bar_count = count($h_bar);
  9.   
  10.   // 전체 화면
  11.   $width = 250;
  12.   $height = 200;
  13.   
  14.   // 간격
  15.   $padding = 5;
  16.   
  17.   // 막대 하나 길이
  18.   $bar_one = $width / $bar_count;
  19.   
  20.   // 이미지 생성
  21.   $im = imagecreate($width, $height);
  22.   $bgc1 = imagecolorallocate ($im, 0xcc, 0xcc, 0xcc);
  23.   $bgc2 = imagecolorallocate ($im, 0x7f, 0x7f, 0x7f);
  24.   $tc   = imagecolorallocate ($im, 0xff, 0xff, 0xff);
  25.   
  26.   // 이미지 배경색
  27.   imagefilledrectangle ($im, 0, 0, $width, $height, $tc);
  28.   
  29.   // 최대값
  30.   $max = max($h_bar);
  31.   
  32.   // 각각의 막대 그림
  33.   for($i = 0; $i < $bar_count; $i++){
  34.     $bar_h = ($height / 100) * (($h_bar[$i] / $max) *100 );
  35.     
  36.     $x1 = $i*$bar_one;
  37.     $y1 = $height - $bar_h;
  38.     $x2 = (($i+1)*$bar_one)-$padding;
  39.     $y2 = $height;
  40.     
  41.     imagefilledrectangle ($im, $x1, $y1, $x2, $y2, $bgc1);
  42.     imagefilledrectangle ($im, $x2, $y1, $x2, $y2, $bgc2);
  43.   }
  44.   
  45.   // 이미지 타입 전송
  46.   header("Content-Type: image/png");
  47.   
  48.   // 이미지 출력
  49.   imagepng($im);
  50.   
  51.   // 이미지 자원 제거
  52.   //imagedestroy($img);
  53.   
  54. ?>

--------------------------------------------------------------------------------------------


막대그래프 그리기1


HTMLtag에서

<img src="imageinsert.php?h_bar?=50,30,15,32,42,13,43">

이런식으로 쓰이면 이미지를 출력합니다.


출처 및 인용 : http://www.php100.com/html/php/lei/2013/0905/4993.html

:
BLOG main image

공지사항

카테고리

분류 (356)
main (1)
php5 (218)
HTML (36)
javascript (93)
IT 이론과 퍼온정보 (8)
깨작일상 (0)
곧 추가할 내용 (0)
추후 알아볼것들... (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

달력

«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Total :
Today : Yesterday :