Skip to content
Server
2013.04.10 08:11

Google Chart API 이용하기

조회 수 20594 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

Google Chart API 이용하기

차트 구현화면

 

1.PNG

 

 

예제

 

http://db.urin79.com/test/stock/stock_value_2013-4-8.php?number=048470&only=0&chart=2&item=2&num1=22&num2=100&num3=121&num4=122

 

소스

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<?
include "dbchk-user.php";
//http://db.urin79.com/test/stock/stock_value_2013-4-8.php?number=083550&only=0&chart=&item=1&num1=&num2=&num3=&num4=&num5=
//http://media.kisline.com/fininfo/mainFininfo.nice?paper_stock=083550&nav=4&header=N
if(!$number)
 {
 $number = '083550';
 }
$loginUrl = 'http://media.kisline.com/fininfo/mainFininfo.nice?paper_stock='.$number.'&nav=4&header=N';
$login_data = '';
$cookie_nm = "./cookie.txt";

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$loginUrl); //접속할 URL 주소
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSLVERSION,1);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_nm);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_nm);
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_data);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);

$string1='<strong>';
$string2='</strong>';

$title=explode($string1,$result);
$title=explode($string2,$title[1]);
$title=$title[0];

echo '<strong>'.$title."</strong></br >";
// ************ $year[1] $year[2] $year[3] $year[4] $year[5] 회계년도 추출 시작 // ************
$string1='<th scope="col">';
$string2='</th>';

$years=explode($string1,$result);

for($i=1;$i<6;$i++)
 {
 $year1 = explode($string2,$years[$i+1]);
 $year[$i] = $year1[0];
 }
// ************ $year[1] $year[2] $year[3] $year[4] $year[5] 회계년도 추출 끝 // ************


// ************ 총자본순이익율/자기자본순이익율/매출액순이익율/매출액영업이익율/매출액법인세비용차감전순이익율/금융비용/매출액비율 // ************
$string1='<span class="depth2">';
$string2='</span>';
$string3='<td class="ctr">';
$string4='</td>';
$values=explode($string1,$result);


// $year[1] $year[2] $year[3] $year[4] $year[5] 회계년도 추출
for($i=1;$i<count($values);$i++)
 {
 if(ereg("</span>",$values[$i]))
  {
//  echo $values[$i];
  $valuea = explode('</span>',$values[$i]);
  $valuelist[$i] = strip_tags($valuea[0]);

  $valuet=explode($string3,$values[$i]);
  $valuer=explode($string4,$valuet[1]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq[$i][1]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[2]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq[$i][2]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[3]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq[$i][3]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[4]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq[$i][4]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[5]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq[$i][5]=strip_tags($valuer[0]);
  }

// echo $i."] ".$valuelist[$i]."<br />";
// echo "($year[1])".$valueq[$i][1]."<br />";
// echo "($year[2])".$valueq[$i][2]."<br />";
// echo "($year[3])".$valueq[$i][3]."<br />";
// echo "($year[4])".$valueq[$i][4]."<br />";
// echo "($year[5])".$valueq[$i][5]."<br /><br />";
 }


// ************ $jaemu[1] => 재무제표,손익계산서 / $jaemu[2] => 현금흐름표
$string1='<div class="section1" name="yt0">';
$string2='</th>';

$jaemu=explode($string1,$result);

//echo $jaemu[1];

$string1='<th scope="row">';
$string2='</th>';
$string3='<td class="rgt">';
$string4='</td>';
$values=explode($string1,$jaemu[1]); // $jaemu[1] <== 재무제표, 손익계산서 구하기

for($i=1;$i<count($values);$i++)
 {
 if(ereg($string2,$values[$i]))
  {
//  echo $values[$i];
  $valuea = explode($string2,$values[$i]);
  $valuelist_heroum[$i] = strip_tags($valuea[0]);

  $valuet=explode($string3,$values[$i]);
  $valuer=explode($string4,$valuet[1]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_heroum[$i][1]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[2]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_heroum[$i][2]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[3]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_heroum[$i][3]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[4]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_heroum[$i][4]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[5]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_heroum[$i][5]=strip_tags($valuer[0]);
  }
// echo $i."] ".$valuelist_heroum[$i]."<br />";
// echo "($year[1])".$valueq__heroum[$i][1]."<br />";
// echo "($year[2])".$valueq_heroum[$i][2]."<br />";
// echo "($year[3])".$valueq_heroum[$i][3]."<br />";
// echo "($year[4])".$valueq_heroum[$i][4]."<br />";
// echo "($year[5])".$valueq_heroum[$i][5]."<br /><br />";
 }

$string1='<th scope="row">';
$string2='</th>';
$string3='<td class="rgt">';
$string4='</td>';
$values=explode($string1,$jaemu[2]);  // $jaemu[2] <== 현금흐름표 구하기

for($i=1;$i<count($values);$i++)
 {
 if(ereg($string2,$values[$i]))
  {
//  echo $values[$i];
  $valuea = explode($string2,$values[$i]);
  $valuelist_jaemu[$i] = strip_tags($valuea[0]);

  $valuet=explode($string3,$values[$i]);
  $valuer=explode($string4,$valuet[1]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_jaemu[$i][1]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[2]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_jaemu[$i][2]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[3]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_jaemu[$i][3]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[4]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_jaemu[$i][4]=strip_tags($valuer[0]);

  $valuer=explode($string4,$valuet[5]);
  if($valuer[0]=='-') $valuer[0]=0;
  $valueq_jaemu[$i][5]=strip_tags($valuer[0]);
  }
// echo $i."] ".$valuelist_jaemu[$i]."<br />";
// echo "($year[1])".$valueq_jaemu[$i][1]."<br />";
// echo "($year[2])".$valueq_jaemu[$i][2]."<br />";
// echo "($year[3])".$valueq_jaemu[$i][3]."<br />";
// echo "($year[4])".$valueq_jaemu[$i][4]."<br />";
// echo "($year[5])".$valueq_jaemu[$i][5]."<br /><br />";
 }

//echo $item."<br />";
//if(!$item) $item=1;
?>
<?

if($only==0)

 {

    echo ' <form>
 <select name="item"> name="website_string"
  <option value="2"  selected="selected"><?=iconv("euc-kr","utf-8","재무제표")?></option>
  <option VALUE="1"><?=iconv("euc-kr","utf-8","손익계산서")?></option>
  <option VALUE="3"><?=iconv("euc-kr","utf-8","현금흐름표")?></option>
 </select>
 <select name="itemname1">
 ';


 for($i=1;$i<count($valuelist)+1;$i++)
  {
  echo '<option value="['.$i.']">'."[".$i."]".$valuelist[$i].'</option>';
  }


 echo ' </select>
 <select name="itemname2">
 ';


 for($i=1;$i<count($valuelist_jaemu)+1;$i++)
  {
  echo '<option value="['.$i.']">'."[".$i."]".$valuelist_jaemu[$i].'</option>';
  }

 echo ' </select>
 <select name="itemname3">
 ';


 for($i=1;$i<count($valuelist_heroum)+1;$i++)
  {
  echo '<option value="['.$i.']">'."[".$i."]".$valuelist_heroum[$i].'</option>';
  }

 echo '
 </select>
 </form>
 ';
 }
?>
<?


for($i=1;$i<6;$i++)
 {
 if($i == 1) $num=$num1;
 if($i == 2) $num=$num2;
 if($i == 3) $num=$num3;
 if($i == 4) $num=$num4;
 if($i == 5) $num=$num5;

 if($i == 1)
  {
  if ($item==1)
   {
   $vitem[0] .= "'".$valuelist[$num]."'";
   $vitem[1] .= str_replace(',','',$valueq[$num][1]);
   $vitem[2] .= str_replace(',','',$valueq[$num][2]);
   $vitem[3] .= str_replace(',','',$valueq[$num][3]);
   $vitem[4] .= str_replace(',','',$valueq[$num][4]);
   $vitem[5] .= str_replace(',','',$valueq[$num][5]);
   }

  if ($item==2)
   {
   $vitem[0] .= "'".$valuelist_jaemu[$num]."'";
   $vitem[1] .= str_replace(',','',$valueq_jaemu[$num][1]);
   $vitem[2] .= str_replace(',','',$valueq_jaemu[$num][2]);
   $vitem[3] .= str_replace(',','',$valueq_jaemu[$num][3]);
   $vitem[4] .= str_replace(',','',$valueq_jaemu[$num][4]);
   $vitem[5] .= str_replace(',','',$valueq_jaemu[$num][5]);
   }

  if ($item==3)
   {
   $vitem[0] .= "'".$valuelist_heroum[$num]."'";
   $vitem[1] .= str_replace(',','',$valueq_heroum[$num][1]);
   $vitem[2] .= str_replace(',','',$valueq_heroum[$num][2]);
   $vitem[3] .= str_replace(',','',$valueq_heroum[$num][3]);
   $vitem[4] .= str_replace(',','',$valueq_heroum[$num][4]);
   $vitem[5] .= str_replace(',','',$valueq_heroum[$num][5]);
   }
  }

 if(($i <> 1) && ($num))
  {
  if ($item==1)
   {
   $vitem[0] .= ",'".$valuelist[$num]."'";
   $vitem[1] .= ",".str_replace(',','',$valueq[$num][1]);
   $vitem[2] .= ",".str_replace(',','',$valueq[$num][2]);
   $vitem[3] .= ",".str_replace(',','',$valueq[$num][3]);
   $vitem[4] .= ",".str_replace(',','',$valueq[$num][4]);
   $vitem[5] .= ",".str_replace(',','',$valueq[$num][5]);
   }

  if ($item==2)
   {
   $vitem[0] .= ",'".$valuelist_jaemu[$num]."'";
   $vitem[1] .= ",".str_replace(',','',$valueq_jaemu[$num][1]);
   $vitem[2] .= ",".str_replace(',','',$valueq_jaemu[$num][2]);
   $vitem[3] .= ",".str_replace(',','',$valueq_jaemu[$num][3]);
   $vitem[4] .= ",".str_replace(',','',$valueq_jaemu[$num][4]);
   $vitem[5] .= ",".str_replace(',','',$valueq_jaemu[$num][5]);
   }

  if ($item==3)
   {
   $vitem[0] .= ",'".$valuelist_heroum[$num]."'";
   $vitem[1] .= str_replace(',','',$valueq_heroum[$num][1]);
   $vitem[2] .= str_replace(',','',$valueq_heroum[$num][2]);
   $vitem[3] .= str_replace(',','',$valueq_heroum[$num][3]);
   $vitem[4] .= str_replace(',','',$valueq_heroum[$num][4]);
   $vitem[5] .= str_replace(',','',$valueq_heroum[$num][5]);
   }
  }
 }
//echo $vitem[0]."<br />".$vitem[1]."<br />".$vitem[2]."<br />".$vitem[3]."<br />".$vitem[4]."<br />".$vitem[5];

?>

<html>
  <head>
    <script type="text/javascript" src="      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Test',<?=$vitem[0]?>],
          ['<?=$year[1]?>',<?=$vitem[1]?>],
          ['<?=$year[2]?>',<?=$vitem[2]?>],
          ['<?=$year[3]?>',<?=$vitem[3]?>],
          ['<?=$year[4]?>',<?=$vitem[4]?>],
          ['<?=$year[5]?>',<?=$vitem[5]?>]
        ]);

        var options = {
          title: 'Company Performance',
          hAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
        };

        var chart = new google.visualization.ColumnChart(document.getElementById('chart_div2'));
        chart.draw(data, options);
      }
    </script>

  </head>
  <body>

<?
if($chart==1)    echo '<div id="chart_div1" style="width: 900px; height: 500px;"></div>';
if($chart==2)    echo '<div id="chart_div2" style="width: 900px; height: 500px;"></div>';
?> 
  </body>
</html>

 

로그인 후 댓글쓰기가 가능합니다.

?

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소