【发布时间】:2019-12-23 03:40:46
【问题描述】:
我有一个格式化的 json 数据,我想在 d3 中使用它来绘制层次结构。它正在处理旧数据,但在 json 数据中添加更多维度后,它会出现以下错误。
类型参数 '{ name: string;孩子:{组:号码;名称:字符串; }[];组:号码; }[]' 不可分配给“只读字符串 []”类型的参数。 键入'{名称:字符串;孩子:{组:号码;名称:字符串; }[];组:号码; }' 不可分配给类型 'string'。
我的重新格式化数据的输出如下,它是使用来自Change Json data into new format by JavaScript链接的@Dacre Denny 的回答中的代码生成的
{
name: "program",
children: (1)[
{
name: "file1",
children: (1)[
{
name: "function1",
calls: (2)[
{
line: 105,
file: "file2",
function: "function5"
},
{
line: 106,
file: "file2",
function: "function6"
}
],
point: (2)[
102,
105
],
point2: (3)[
(2)[
102,
102
],
(3)[
105,
106,
107
],
(2)[
106,
107
]
],
group: 1
}
],
group: 1
}
],
group: 0
}
我现有的 d3 代码 sn-p 如下:
const data = TestFunction.test(); //from here i am calling the reformatted output
const root = d3.hierarchy(data);
const colorScale = d3.scaleOrdinal()
.domain(data.children) // here its showing the error.
.range(d3.schemeCategory10);
非常感谢您的帮助。
【问题讨论】:
标签: javascript json string object d3.js