- Google Chart 指南
- Google Charts - 首頁
- Google Chart - 概覽
- Google Chart - 環境設定
- 設定語法
- Google Chart - 面積圖
- Google Chart - 條形圖
- Google Chart - 氣泡圖
- Google Chart - 日曆圖
- Google Chart - 蠟燭圖
- Google Chart - 柱狀圖
- Google Chart - 組合圖
- Google Chart - 直方圖
- Google Chart - 折線圖
- Google Chart - 地圖
- Google Chart - 組織結構圖
- Google Chart - 餅圖
- Google Chart - 桑基圖
- Google Chart - 散點圖
- 折線面積圖
- Google Chart - 表格圖
- Google Chart - 時間表圖
- Google Chart - 樹形圖
- Google Chart - 趨勢線圖
- Google Chart 實用資源
- Google Chart - 快速指南
- Google Chart - 實用資源
- Google Chart - 討論
Google Chart - 條形圖
以下是條形圖示例。 我們已經在 Google Chart 設定語法 章節中瞭解了用於繪製此圖的設定。所以讓我們看看完整的示例。
設定
我們使用 **Bar** 類來展示條形圖。
//classic chart
var chart = new google.visualization.BarChart(document.getElementById('container'));
//Material chart
var chart = new google.charts.Bar(document.getElementById('container'));
//set the bar to be horizontal using options
var options = {
bars: 'horizontal'
};
示例
googlecharts_bar_material.htm
<html>
<head>
<title>Google Charts Tutorial</title>
<script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js">
</script>
<script type = "text/javascript">
google.charts.load('current', {packages: ['corechart','bar']});
</script>
</head>
<body>
<div id = "container" style = "width: 550px; height: 400px; margin: 0 auto">
</div>
<script language = "JavaScript">
function drawChart() {
// Define the chart to be drawn.
var data = google.visualization.arrayToDataTable([
['Year', 'Asia', 'Europe'],
['2012', 900, 390],
['2013', 1000, 400],
['2014', 1170, 440],
['2015', 1250, 480],
['2016', 1530, 540]
]);
var options = {title: 'Population (in millions)', bars: 'horizontal'};
// Instantiate and draw the chart.
var chart = new google.charts.Bar(document.getElementById('container'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
</script>
</body>
</html>
結果
驗證結果。
googlecharts_bar_charts.htm
廣告