【发布时间】:2026-02-15 02:55:01
【问题描述】:
我正在使用 D3v5 和 React。
我有这个数据
{
"name": "main",
"children": [
{
"name": "testedin",
"children": [
{
"name":"positive",
"value": 53,
"floor":2
},
{
"name":"negative",
"value": 24,
"floor":2
},
{
"name":"unknown",
"value": 23,
"floor":2
}
],
"floor":1,
"value":55
},
{
"name": "Not tested",
"value": 45,
"floor":1
}
],
"floor":0
}
我想画这个图表,其中第二列rects的数据是第一列rect父级的百分比值。
我遵循了这个例子:icecle Chart,一切正常。
问题在于,由于这段代码,图表中的值只是总结起来:
const partition = data => {
const root = d3.hierarchy(data)
.sum(d => d.value)
.sort((a, b) => b.height - a.height || b.value - a.value);
return d3.partition()
.size([height, (root.height + 1) * width / 4])
(root);
}
我尝试更改 sum 函数,以便对值有不同的用法,但找不到编辑它的方法,以便获得百分比。
【问题讨论】:
标签: reactjs typescript d3.js charts hierarchy