Skip to content

Instantly share code, notes, and snippets.

@vexus2
Last active December 10, 2015 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexus2/4371922 to your computer and use it in GitHub Desktop.
Save vexus2/4371922 to your computer and use it in GitHub Desktop.
[JS]GoogleChartAPIにて棒グラフ出力用テンプレート。 別途json出力用APIは必要。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages:['corechart']});
</script>
<script type="text/javascript">
(function () {
drawGraph = function () {
$.ajax({
type :"GET",
url :"<?php echo ADMIN_URL;?>api/overview_register_user",
dataType:'json',
success :function (json) {
google.load("visualization", "1", {packages:["corechart"]});
drawChart(json);
},
error :function (XMLHttpRequest, textStatus, errorThrown) {
alert('エラーが発生しました。再度ログインしなおしてください。');
}
});
};
drawChart = function (json) {
arr = new Array();
arr.push(['日にち', '登録者数']);
$.each(json, function (i, v) {
arr.push([v[0].regist_date, parseInt(v[0].count)]);
});
var data = google.visualization.arrayToDataTable(arr);
var options = {
title:'ゲスト・本会員登録者数/日',
hAxis:{title:'登録日', titleTextStyle:{color:'black'}}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
google.setOnLoadCallback(drawGraph());
})();
</script>
<div id="chart_div"
style="width: 900px; height: 500px;"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment