- 谷歌图表教程
- 谷歌图表 - 主页
- Google 图表 - 概述
- Google 图表 - 环境设置
- 配置语法
- Google 图表 - 面积图
- Google Charts - 条形图
- Google 图表 - 气泡图
- Google 图表 - 日历图表
- Google 图表 - 烛台图
- Google 图表 - 柱形图
- Google 图表 - 组合图表
- Google Charts - 直方图
- Google 图表 - 折线图
- Google 图表 - 地图
- Google 图表 - 组织结构图
- Google 图表 - 饼图
- 谷歌图表 - 桑基图表
- Google 图表 - 散点图
- 阶梯面积图
- Google 图表 - 表格图表
- Google Charts - 时间线图表
- Google 图表 - 树形图图表
- Google 图表 - 趋势线图表
- 谷歌图表有用的资源
- Google 图表 - 快速指南
- Google 图表 - 有用的资源
- 谷歌图表 - 讨论
Google 图表 - 树形图图表
TreeMap 是数据树的可视化表示,其中每个节点可能有零个或多个子节点以及一个父节点(根除外)。每个节点都显示为一个矩形,可以根据我们分配的值调整大小和颜色。大小和颜色的值是相对于图中所有其他节点而言的。以下是树形图的示例。我们已经在Google Charts 配置语法一章中看到了用于绘制此图表的配置。那么,让我们看一下完整的示例。
配置
我们使用TreeMap类来显示树状图。
//TreeMap chart
var chart = new google.visualization.TreeMap(document.getElementById('container'));
例子
googlecharts_treemap.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" src = "https://www.google.com/jsapi">
</script>
<script type = "text/javascript">
google.charts.load('current', {packages: ['treemap']});
</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();
var data = google.visualization.arrayToDataTable([
['Location', 'Parent', 'Market trade volume (size)', 'Market increase/decrease (color)'],
['Global', null, 0, 0],
['America', 'Global', 0, 0],
['Europe', 'Global', 0, 0],
['Asia', 'Global', 0, 0],
['Australia', 'Global', 0, 0],
['Africa', 'Global', 0, 0],
['USA', 'America', 52, 31],
['Mexico', 'America', 24, 12],
['Canada', 'America', 16, -23],
['France', 'Europe', 42, -11],
['Germany', 'Europe', 31, -2],
['Sweden', 'Europe', 22, -13],
['China', 'Asia', 36, 4],
['Japan', 'Asia', 20, -12],
['India', 'Asia', 40, 63],
['Egypt', 'Africa', 21, 0],
['Congo', 'Africa', 10, 12],
['Zaire', 'Africa', 8, 10]
]);
var options = {
minColor: '#f00',
midColor: '#ddd',
maxColor: '#0d0',
headerHeight: 15,
fontColor: 'black',
showScale: true
};
// Instantiate and draw the chart.
var chart = new google.visualization.TreeMap(document.getElementById('container'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
</script>
</body>
</html>
结果
验证结果。