- 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 图表 - 表格图表
表格图可帮助渲染可排序和分页的表格。表格单元格可以使用格式字符串进行格式化,或通过将 HTML 直接插入作为单元格值。默认情况下,数值右对齐;布尔值显示为对号或叉号。用户可以用键盘或鼠标选择单行。列头可用于排序。在滚动过程中,标题行保持固定。表格会触发与用户交互相对应的事件。我们已经看到 Google 图表配置语法 章节中用来绘制此图表的配置。因此,我们来看看完整的示例。
配置
我们用过 **Table** 类来显示基于表的图表。
//table chart
var chart = new google.visualization.Table(document.getElementById('container'));
示例
googlecharts_table_chart.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: ['table']});
</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', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time Employee');
data.addRows([
['Mike', {v: 10000, f: '$10,000'}, true],
['Jim', {v:8000, f: '$8,000'}, false],
['Alice', {v: 12500, f: '$12,500'}, true],
['Bob', {v: 7000, f: '$7,000'}, true]
]);
var options = {
showRowNumber: true,
width: '100%',
height: '100%'
};
// Instantiate and draw the chart.
var chart = new google.visualization.Table(document.getElementById('container'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
</script>
</body>
</html>
结果
验证结果。
广告