有没有办法在Google Charts的TreeMap中显示子标签 [英] Is there a way to display the children labels in Google Charts' TreeMap
问题描述
我正在尝试使用Google Charts创建一个TreeMap,它不仅显示父标签以及孩子的颜色分类,还显示孩子的标签。我基本上想要这个(保存可能的儿童颜色):
I'm trying to create a TreeMap using Google Charts that not only shows the parent label along with the children's color breakdowns, but also the children's labels. I basically want this (save possible children coloration):
我还没有找到任何在线示例或问题,这可能吗?
I haven't found any online examples or questions on it, is this possible?
推荐答案
不确定你是否能完全像图片,
但是如果你想要显示父标签和子标签,
使用选项 - > maxDepth:2
not sure that you can get exactly like the picture,
but if you want to show both the parent and child labels,
use option --> maxDepth: 2
注意:不允许重复的子ID,
这里,对象表示法用于提供唯一的ID,
但仍然在多个节点上显示相同的名称
note: duplicate child id's are not allowed,
here, object notation is used to provide a unique id,
but still display the same name on multiple nodes
{v: 'Rick0', f: 'Rick'}
{v: 'Rick1', f: 'Rick'}
其中...
v:
= value
f:
= 格式化值
where...
v:
= value
f:
= formatted value
请参阅以下工作sni ppet ...
see following working snippet...
google.charts.load('current', {
packages: ['treemap']
}).then(function () {
var data = google.visualization.arrayToDataTable([
['Person', 'Fruit', 'Size', 'Color'],
['Global', null, 0, 0],
['Bananas', 'Global', 0, 0],
[{v: 'Rick0', f: 'Rick'}, 'Bananas', 100, 0],
[{v: 'Anne0', f: 'Anne'}, 'Bananas', 40, 0],
[{v: 'Peter0', f: 'Peter'}, 'Bananas', 5, 0],
['Apples', 'Global', 0, 0],
[{v: 'Anne1', f: 'Anne'}, 'Apples', 20, 2],
[{v: 'Peter1', f: 'Peter'}, 'Apples', 20, 2],
[{v: 'Rick1', f: 'Rick'}, 'Apples', 15, 2],
['Oranges', 'Global', 0, 0],
[{v: 'Rick2', f: 'Rick'}, 'Oranges', 20, 1],
[{v: 'Peter2', f: 'Peter'}, 'Oranges', 20, 1],
[{v: 'Anne2', f: 'Anne'}, 'Oranges', 10, 1],
['Susanne', 'Global', 10, null]
]);
tree = new google.visualization.TreeMap(document.getElementById('chart_div'));
tree.draw(data, {
maxDepth: 2,
minColor: 'yellow',
midColor: 'orange',
maxColor: 'red',
noColor: 'lime',
});
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
这篇关于有没有办法在Google Charts的TreeMap中显示子标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!