我有一个格式化的 json 数据,我想在 d3 中使用它来绘制层次结构。它正在处理旧数据,但在 json 数据中添加更多维度后,出现以下错误。
类型参数 '{ name: string;孩子们:{ 组:数量;名称:字符串; }[];组:数量; }[]' 不可分配给“只读字符串[]”类型的参数。
输入 '{ 名称:字符串;孩子们:{ 组:数量;名称:字符串; }[];组:数量; }' 不可分配给类型“string”。
我重新格式化的数据的输出如下,它是使用 @Dacre Denny 的答案中的代码生成的通过 JavaScript 将 Json 数据更改为新格式 https://stackoverflow.com/questions/59448748/change-json-data-into-new-format-by-javascript/59448945?noredirect=1#comment105082157_59448945 link
{
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 代码片段如下:
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);
我将衷心感谢您的帮助。