Javascript 日暴图-添加额外的数据层
我将遵循本教程: 它工作正常,但只有两个数据“环”。我想加上第三个。它正在从data.json文件中提取包含以下数据的数据:Javascript 日暴图-添加额外的数据层,javascript,json,d3.js,graph,Javascript,Json,D3.js,Graph,我将遵循本教程: 它工作正常,但只有两个数据“环”。我想加上第三个。它正在从data.json文件中提取包含以下数据的数据: { "name": "TOPICS", "children": [{ "name": "Topic A", "children": [{"name": "Sub A1", "size": 5, "text": "A story", "sentiment": 1, "source": "dictionary"},
{
"name": "TOPICS", "children": [{
"name": "Topic A",
"children": [{"name": "Sub A1", "size": 5, "text": "A story", "sentiment": 1, "source": "dictionary"},
{"name": "Sub A2", "size": 5, "text": "A note", "sentiment": 0.5, "source": "dictionary"}]
}, {
"name": "Topic B",
"children": [{"name": "Sub B1", "size": 5, "text": "A vignette", "sentiment": 1, "source": "newspaper"},
{"name": "Sub B3", "size": 5, "text": "A joke", "sentiment": 0.5, "source": "email"}]
}, {
"name": "Topic C",
"children": [{"name": "Sub A1", "size": 5, "text": "A narrative", "sentiment": 1, "source": "newspaper"},
{"name": "Sub A2", "size": 5, "text": "A chronology", "sentiment": 0.5, "source": "email"}]
}]
}
我的问题是,如何在外部添加第三环数据?这似乎是JSON格式的,但我无法理解它。鉴于您共享的特定bl.ock,您需要做的就是在您希望成为新层父级的项内创建一个
子项数组,并删除父级的size
属性:
例如,在子A1中创建一个新层:
{
"name": "TOPICS",
"children": [{
"name": "Topic A",
"children": [{
"name": "Sub A1",
"text": "A story",
"sentiment": 0.8,
"source": "dictionary",
"children": [{
"name": "New Layer 1",
"size": 5,
"text": "A story",
"sentiment": 0.8,
"source": "dictionary"
},{
...etc
}]
}, {
"name": "Sub A2",
"size": 5,
"text": "A note",
"sentiment": 0.3,
"source": "dictionary"
}]
},{
...etc
}]
}
我只是在这里复制/粘贴。。。当然,您必须相应地调整这些值
以下是更新的bl.ocks: