是否可以在调用任何列时创建树状图 "value"
Is it possible to create a treemap when any column is called "value"
我是 d3 的新手,我尝试创建一个树状图。
我注意到当密钥被命名为 "value" 时我的代码可以工作,而如果我调用我的密钥 "size" 则不会。
我的问题从第一行开始:
d3.json("dataZC.json", function(err, data)
{
var treemap =d3.layout.treemap()
.size([500,500])
.nodes(data);
console.log(treemap);
}
我的数据是这样的
{
"name": "flare",
"children": [
{"name": "analytics",
"children": [
{"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
{"name": "CommunityStructure", "size": 3812},
{"name": "HierarchicalCluster", "size": 6714},
{"name": "MergeEdge", "size": 743}
]},
{
"name": "graph",
"children": [
{"name": "BetweennessCentrality", "size": 3534},
{"name": "LinkDistance", "size": 5731},
{"name": "MaxFlowMinCut", "size": 7840},
{"name": "ShortestPaths", "size": 5914},
{"name": "SpanningTree", "size": 3416}
]}
,........
]}
]}
如果有人有任何键使用树图的解决方案,我将不胜感激。
谢谢
来自fine manual :
treemap.value([value])
If value is specified, sets the value accessor to the specified function. If value is not specified, returns the current value accessor, which assumes that the input data is an object with a numeric value
attribute:
function value(d) {
return d.value;
}
使用
treemap = d3.layout.treemap()
.value(function(d) {
return d.size;
})
我是 d3 的新手,我尝试创建一个树状图。 我注意到当密钥被命名为 "value" 时我的代码可以工作,而如果我调用我的密钥 "size" 则不会。
我的问题从第一行开始:
d3.json("dataZC.json", function(err, data)
{
var treemap =d3.layout.treemap()
.size([500,500])
.nodes(data);
console.log(treemap);
}
我的数据是这样的
{
"name": "flare",
"children": [
{"name": "analytics",
"children": [
{"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
{"name": "CommunityStructure", "size": 3812},
{"name": "HierarchicalCluster", "size": 6714},
{"name": "MergeEdge", "size": 743}
]},
{
"name": "graph",
"children": [
{"name": "BetweennessCentrality", "size": 3534},
{"name": "LinkDistance", "size": 5731},
{"name": "MaxFlowMinCut", "size": 7840},
{"name": "ShortestPaths", "size": 5914},
{"name": "SpanningTree", "size": 3416}
]}
,........
]}
]}
如果有人有任何键使用树图的解决方案,我将不胜感激。 谢谢
来自fine manual :
treemap.value([value])
If value is specified, sets the value accessor to the specified function. If value is not specified, returns the current value accessor, which assumes that the input data is an object with a numericvalue
attribute:function value(d) { return d.value; }
使用
treemap = d3.layout.treemap()
.value(function(d) {
return d.size;
})