"구글차트 PHP 연동"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
잔글 (PSR 규칙에 맞게 서식수정)
8번째 줄: 8번째 줄:
<syntaxhighlight lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
$data = array(
$data = [
array('원소', '밀도'),
    ['원소', '밀도'],
array('구리', 8.94),
    ['구리', 8.94],
array('은', 10.49),
    ['은', 10.49],
array('금', 19.30),
    ['금', 19.30],
array('백금', 21.45),
    ['백금', 21.45],
);
];
$options = array(
$options = [
'title' => '귀금속 밀도 (단위: g/cm³)',
    'title' => '귀금속 밀도 (단위: g/cm³)',
'width' => 400, 'height' => 500
    'width' => 400, 'height' => 500
);
];
?>
?>
<script src="//www.google.com/jsapi"></script>
<script src="//www.google.com/jsapi"></script>

2022년 4월 2일 (토) 09:31 판

1 개요

구글차트 PHP 연동
구글 차트 API - PHP 연동

2 예시

<?php
$data = [
    ['원소', '밀도'],
    ['구리', 8.94],
    ['은', 10.49],
    ['금', 19.30],
    ['백금', 21.45],
];
$options = [
    'title' => '귀금속 밀도 (단위: g/cm³)',
    'width' => 400, 'height' => 500
];
?>
<script src="//www.google.com/jsapi"></script>
<script>
var data = <?= json_encode($data) ?>;
var options = <?= json_encode($options) ?>;
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(function() {
  var chart = new google.visualization.ColumnChart(document.querySelector('#chart_div'));
  chart.draw(google.visualization.arrayToDataTable(data), options);
});
</script>
<div id="chart_div"></div>
→ 예제: http://example.zetawiki.com/gchart/first-php.php

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}