- 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
广告