PHP 단순 막대 챠트 (Bar Chart)
페이지 정보
첨부파일
-
line.zip (1.8K)
79회 다운로드 | DATE : 2013-05-11 21:40:38
본문
단순하게 막대그래프를 그리는 방법입니다.
구글 Bar Charts API를 사용해도 되지만 너무나 단순한 설문결과를 보여주는 방식이라서 기냥 만들었습니다.
<?php
// 설문1
$sql = "SELECT sum(song01) as song01Y FROM 테이블 where song01 = '1'"; // 찬성
$result = mysql_query($sql);
$total01Y = mysql_result($result,0,0);
$sql = "SELECT sum(song01) as song01N FROM 테이블 where song01 = '2'"; // 반대
$result = mysql_query($sql);
$total01N = mysql_result($result,0,0);
$total01 = $total01Y + $total01N;
$total01Yp = round(($total01Y / $total01 *100),2);
$total01Np = 100 - $total01Yp;
// 설문2
$sql = "SELECT sum(song02) as song02Y FROM 테이블 where song02 = '1'"; // 찬성
$result = mysql_query($sql);
$total02Y = mysql_result($result,0,0);
$sql = "SELECT sum(song02) as song02N FROM 테이블 where song02 = '2'"; // 반대
$result = mysql_query($sql);
$total02N = mysql_result($result,0,0);
$total02 = $total02Y + $total02N;
$total02Yp = round(($total02Y / $total02 *100),2);
$total02Np = 100 - $total02Yp;
?>
1. 투표1<br />
① 필요하다.<br />
<img src='line_01.gif' style='width:<?php echo (2.80 * $total_song01Yp); ?>px; height:13px' /> <?php echo $total_song01Y; ?>명(<?php echo $total_song01Yp; ?>%)<br />
② 필요하지 않다.<br />
<img src='line_02.gif' style='width:<?php echo (2.80 * $total_song01Np); ?>px; height:13px' /> <?php echo $total_song01N; ?>명(<?php echo $total_song01Np; ?>%)<br />
<br />
2. 투표2<br />
① 동의한다.
<img src='line_01.gif' style='width:<?php echo (2.80 * $total_song02Yp); ?>px; height:13px' /> <?php echo $total_song02Y; ?>명(<?php echo $total_song02Yp; ?>%)<br />
② 동의하지 않는다.<br />
<img src='line_02.gif' style='width:<?php echo (2.80 * $total_song02Np); ?>px; height:13px' /> <?php echo $total_song02N; ?>명(<?php echo $total_song02Np; ?>%)
구글 Bar Charts API를 사용해도 되지만 너무나 단순한 설문결과를 보여주는 방식이라서 기냥 만들었습니다.
<?php
// 설문1
$sql = "SELECT sum(song01) as song01Y FROM 테이블 where song01 = '1'"; // 찬성
$result = mysql_query($sql);
$total01Y = mysql_result($result,0,0);
$sql = "SELECT sum(song01) as song01N FROM 테이블 where song01 = '2'"; // 반대
$result = mysql_query($sql);
$total01N = mysql_result($result,0,0);
$total01 = $total01Y + $total01N;
$total01Yp = round(($total01Y / $total01 *100),2);
$total01Np = 100 - $total01Yp;
// 설문2
$sql = "SELECT sum(song02) as song02Y FROM 테이블 where song02 = '1'"; // 찬성
$result = mysql_query($sql);
$total02Y = mysql_result($result,0,0);
$sql = "SELECT sum(song02) as song02N FROM 테이블 where song02 = '2'"; // 반대
$result = mysql_query($sql);
$total02N = mysql_result($result,0,0);
$total02 = $total02Y + $total02N;
$total02Yp = round(($total02Y / $total02 *100),2);
$total02Np = 100 - $total02Yp;
?>
1. 투표1<br />
① 필요하다.<br />
<img src='line_01.gif' style='width:<?php echo (2.80 * $total_song01Yp); ?>px; height:13px' /> <?php echo $total_song01Y; ?>명(<?php echo $total_song01Yp; ?>%)<br />
② 필요하지 않다.<br />
<img src='line_02.gif' style='width:<?php echo (2.80 * $total_song01Np); ?>px; height:13px' /> <?php echo $total_song01N; ?>명(<?php echo $total_song01Np; ?>%)<br />
<br />
2. 투표2<br />
① 동의한다.
<img src='line_01.gif' style='width:<?php echo (2.80 * $total_song02Yp); ?>px; height:13px' /> <?php echo $total_song02Y; ?>명(<?php echo $total_song02Yp; ?>%)<br />
② 동의하지 않는다.<br />
<img src='line_02.gif' style='width:<?php echo (2.80 * $total_song02Np); ?>px; height:13px' /> <?php echo $total_song02N; ?>명(<?php echo $total_song02Np; ?>%)
댓글목록
등록된 댓글이 없습니다.