- Google 图表教程
- Google 图表 - 首页
- Google 图表 - 概述
- Google 图表 - 环境设置
- 配置语法
- Google 图表 - 区域图表
- Google 图表 - 条形图表
- Google 图表 - 气泡图
- Google 图表 - 日历图表
- Google 图表 - 蜡烛棒图
- Google 图表 - 柱形图
- Google 图表 - 组合图表
- Google 图表 - 直方图
- Google 图表 - 折线图
- Google 图表 - 地图
- Google 图表 - 组织结构图
- Google 图表 - 饼图
- Google 图表 - 桑基图
- Google 图表 - 散点图
- 阶梯区域图
- Google 图表 - 表格图表
- Google 图表 - 时间轴图表
- Google 图表 - 树状图
- Google 图表 - 趋势线图
- Google 图表 - 有用资源
- Google 图表 - 快速指南
- Google 图表 - 有用资源
- Google 图表 - 讨论
Google 图表 - 基本饼图
以下是一个基本饼图示例。我们已在 Google 图表配置语法 章节中了解过绘制此图所用的配置。因此,让我们看看完整示例。
配置
我们使用 PieChart 类来显示基于饼图的图表。
//pie chart
var chart = new google.visualization.PieChart(document.getElementById('container'));
示例
googlecharts_pie_basic.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']});
</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 = new google.visualization.DataTable();
data.addColumn('string', 'Browser');
data.addColumn('number', 'Percentage');
data.addRows([
['Firefox', 45.0],
['IE', 26.8],
['Chrome', 12.8],
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]);
// Set chart options
var options = {
'title':'Browser market shares at a specific website, 2014',
'width':550,
'height':400
};
// Instantiate and draw the chart.
var chart = new google.visualization.PieChart(document.getElementById('container'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
</script>
</body>
</html>
结果
核实结果。
googlecharts_pie_charts.htm
广告