Last active
January 10, 2018 06:19
-
-
Save externvoid/c949b85a220b9323d06e3677418a82e9 to your computer and use it in GitHub Desktop.
google chartサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- http://www.itdashboard.go.jp/DataFeeds/sampleGc --> | |
| <!-- jQueryのgetJSONでjsonを取って来て、jsonData変数へ格納 --> | |
| <!-- jsonData.raw_dataは配列でjsonData.raw_data[0], jsonData.raw_data[1]...って --> | |
| <!-- 感じでアクセスできる。 --> | |
| <!-- 入っている要素はjson。 --> | |
| <!-- こいつをgoogle.visualization.DataTable型のdataへ放り込めば良い! --><!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Sample Google Charts</title> | |
| <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
| <script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
| <script> | |
| google.load("visualization", "1", { | |
| packages: ["corechart"] | |
| }); | |
| google.setOnLoadCallback(drawChart); | |
| function drawChart() { | |
| $.getJSON("http://www.itdashboard.go.jp/PublicApi/getData.json?dataset=BasicInformation&year=2014&field=organization&option=count", | |
| function(jsonData) { | |
| // ========== データ設定 ========== | |
| var data = new google.visualization.DataTable(); | |
| data.addRows(jsonData.raw_data.length); | |
| data.addColumn("string", "府省名"); | |
| data.addColumn("number", "システム数"); | |
| $.each(jsonData.raw_data, function(i, v) { | |
| data.setValue(i, 0, v.organization); | |
| data.setValue(i, 1, v.count); | |
| }); | |
| // ========== 表示設定 ========== | |
| var options = { | |
| title: "府省別システム数", | |
| chartArea: { | |
| width: "50%", | |
| height: "90%" | |
| }, | |
| vAxis: { | |
| title: "府省名" | |
| } | |
| }; | |
| // ========== 描画処理 ========== | |
| var chart = new google.visualization.BarChart(document.getElementById("chart_div")); | |
| chart.draw(data, options); | |
| }); | |
| } | |
| </script> | |
| <style> | |
| div#chart_div { | |
| height: 400px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="chart_div"></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment