본문 바로가기

Programming/PHP

PHP 막대그래프2

아래 작성했던거에... 나름 버전업 이랄까 ...

좀더 깔끔하게 수정함.

 

<?php
/* ================================================================
 * filename  :  gra.php
 * Creator  :  lcy0227, 2009. 02. 21
 * Comment :  그래프 그리기
 ==================================================================*/

 
 /**
  * $y_step_cnt = Y축 눈금개수
  * $arrVal = X축 눈금이 Key, Y축 눈금이 Value
  */
function showStickGraph($y_step_cnt, $arrVal, $arrNetSales)
{       
 $maxVal =  max($arrVal);
 $minVal = 0;
 
 $step = round($maxVal / $y_step_cnt);  // y축 눈금
 
 $unitHight = 30;        // 단위 높이 픽셀값
 $bottomCommentHeight= 20;    // 하단 설명공간 높이 픽셀값
 $unitName="만";
 
 //echo  "arrNetSales : ".print_r($arrNetSales);
 
?>
 (단위:<?=$unitName?>원)
 <table cellpadding=0 cellspacing=0 style="border:1px solid black" bgcolor="gray">
  <tr>
   
   <!-- y축-->
   <td width="40" style="border-right:1px solid black">
     <table cellpadding=0 cellspacing=0 border="0" width="100%">
      
      <? for ($a= $maxVal; $a >= $minVal; $a -= $step){ ?>
      <tr>
       <td height="<?=$unitHight?>" valign="bottom" align="right">
        <font size="1" color="black"><?=$a?></font>
       </td>
      </tr>
      <?}?>
      
      <tr>
       <td height="<?=$bottomCommentHeight?>">
        <font size="1" color="black">매출</font></td>
      </tr>
      
     </table>
 
    </td>
   
   <!--x축-->
   <td valign="bottom"> 
    <table cellpadding=0 cellspacing=0 border="0" bgcolor="gray">
     <tr>
      <? foreach($arrVal as $key => $value){ ?>

       <td valign="bottom" align="center">
        <div><font size="1" color="black"><?=$value?><br><?if(isset($arrNetSales[$key])){echo"($arrNetSales[$key])";}?></font></div>
        <img src="graph.jpg" height="<?= ($value/$step) * $unitHight ?>" width="15"/>
       </td>
        
      <?}?>
     </tr>
     
     <tr style="border-top:1px solid black">
      <? foreach($arrVal as $key => $value){ ?>
       <td height="<?=$bottomCommentHeight?>" valigh="top" align="center" style="border-top:1px solid black;border-right:1px solid black;">
        <font size="1" color="black"><?=str_replace("-", "/", substr($key, -5))?></font></td>
        <?}?>
     </tr>
    <table>
   </td>
   </tr>
     
 </table>

<?
}
?>


'Programming > PHP' 카테고리의 다른 글

PHP로 만들어본 간단한 막대그래프  (0) 2009.08.31
PHP 소수점 표시(몇번쨰 이하 버림)  (0) 2009.08.31
PHP 배열 함수 목록  (0) 2009.08.31
PHP 파일업로드  (0) 2009.08.31