Javascript 如何将url中的json值应用于双层分区D3布局
第三天过去了,我无法更改双层分区(或Sunburst)d3的代码来显示我的数据。 我使用以下json代码实现了此布局:Javascript 如何将url中的json值应用于双层分区D3布局,javascript,json,d3.js,Javascript,Json,D3.js,第三天过去了,我无法更改双层分区(或Sunburst)d3的代码来显示我的数据。 我使用以下json代码实现了此布局: { "children": [ { "name": "المصاريف", "children": [ { "name": "Expense_1", "colour": "rgba(255, 148, 42)", "children": [ {
{
"children": [
{
"name": "المصاريف",
"children": [
{
"name": "Expense_1",
"colour": "rgba(255, 148, 42)",
"children": [
{
"name": "ExpSubCat1_1",
"size": 8,
"colour": "rgba(255, 148, 42,0.95)"
},
{
"name": "ExpSubCat1_6",
"size": 15,
"colour": "rgba(255, 148, 42,0.45)"
},
]
},
{
"name": "Expense_2",
"colour": "rgb(255, 148, 42)",
"children": [
{
"name": "ExpSubCat2_1",
"size": 10,
"colour": "rgba(255, 148, 42,0.75)"
},
{
"name": "ExpSubCat2_2",
"size": 5,
"colour": "rgba(255, 148, 42,0.65)"
}
]
}
]
},
]
}
这是我的json数据,来自url:
因此,我需要更改布局以接受我的json数据并将节点添加到圆中,但以下是我所做的,没有结果…:
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: '{{ url_for("diffs.api_domains", file_id=file.id) }}',
dataType: 'json'
}).done(function(result, error) {
partition
.value(function(d) { return d.size; })
.nodes(error)
.forEach(function(d) {
d.sum = d.value;
});
.value(function(d) { return d.sum; });
var g = svg.selectAll("g")
.data(partition.nodes(result))
.enter().append("g");
var path = g.append("path")
.attr("d", arc)
.style("fill", function(d) { return color(d.name); })
.on("click", click)
.each(stash);
});
我的数据被添加到result
参数中,我认为d.name
、d.size
和d.value
必须替换为我的json中的数据参数,但我不知道需要做什么更改
如果你知道如何解决这个问题,任何提示或解决方案都会对我有很大帮助。如果我的解释不清楚或者有什么不合理的地方,请告诉我