Googlecharts 简明教程
Google Charts - Table Chart
表格图表用于呈现一个可以排序和翻页的表格。可以使用格式字符串或直接插入 HTML 作为单元格值来设置表格单元格的格式。默认情况下,数值右对齐;布尔值显示为对号或错号。用户可以使用键盘或鼠标选择单行。可以使用列标题进行排序。在滚动期间,标题行保持固定。该表格触发与用户交互对应的事件。我们已经在 Google Charts Configuration Syntax 章中了解了用于绘制此图表的配置。因此,我们来看看一个完整示例。
Configurations
我们使用了 Table 类来显示基于表格的图表。
//table chart
var chart = new google.visualization.Table(document.getElementById('container'));
Example
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>