Javascript 如何使用饼图读取d3中的json文件?

Javascript 如何使用饼图读取d3中的json文件?,javascript,jquery,json,d3.js,Javascript,Jquery,Json,D3.js,我正在尝试使用d3lib制作饼图。我首先尝试使用csv文件。它工作正常 这是我的密码 但是 当我使用json文件而不是csv文件时,它不会显示pie图表 这是我的密码 doc 获取json的回调函数设置不同(较旧的样式) 在我得到代码后,我调查并确认了回调是如何发送的。在没有任何错误的良好请求上传递(null,data)。仅通过错误的请求(错误) 下面是它的外观 d3.json("data.json", function(error, data) { if (error) throw

我正在尝试使用
d3
lib
制作饼图。我首先尝试使用
csv
文件。它工作正常 这是我的密码

但是 当我使用
json
文件而不是
csv
文件时,它不会显示
pie
图表

这是我的密码

doc


获取json的回调函数设置不同(较旧的样式)

在我得到代码后,我调查并确认了回调是如何发送的。在没有任何错误的良好请求上传递(null,data)。仅通过错误的请求(错误)

下面是它的外观

d3.json("data.json", function(error, data) {
    if (error) throw error;

    var arc = g.selectAll(".arc")
        .data(pie(data))
        .enter().append("g")
        .attr("class", "arc");

    arc.append("path")
        .attr("d", path)
        .attr("fill", function(d) {
            return color(d.data.age);
        });

    arc.append("text")
        .attr("transform", function(d) {
            return "translate(" + label.centroid(d) + ")";
        })
        .attr("dy", "0.35em")
        .text(function(d) {
            return d.data.age;
        });
});
还有这个的复制品:还有这个:
d3.json("data.json", function(error, data) {
    if (error) throw error;

    var arc = g.selectAll(".arc")
        .data(pie(data))
        .enter().append("g")
        .attr("class", "arc");

    arc.append("path")
        .attr("d", path)
        .attr("fill", function(d) {
            return color(d.data.age);
        });

    arc.append("text")
        .attr("transform", function(d) {
            return "translate(" + label.centroid(d) + ")";
        })
        .attr("dy", "0.35em")
        .text(function(d) {
            return d.data.age;
        });
});