设置弧的d属性时出错

时间:2013-05-07 13:32:26

标签: javascript d3.js

当我使用d3.js库处理饼图时,我的浏览器会给我两个错误。

Error: Problem parsing d="M1.4695276245868527e-14,-240A240,240 0 1,1 NaN,NaNL0,0Z"
Error: Problem parsing d="MNaN,NaNA240,240 0 1,1 NaN,NaNL0,0Z"

以下是我的代码的一部分:

var arc = d3.svg.arc()
        .outerRadius(radius - 10)
        .innerRadius(0);

d3.json('...', function (error, json) {

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

    g.append("path")
        .attr("d", arc) // <-- problem
        .style("fill", function(d, i) {
            console.log(d.data.count);
            return color(d.data.count);
        });
});

我真的很感谢你的帮助,因为我发现d3.js是一个很好的帮助。祝你有愉快的一天。

1 个答案:

答案 0 :(得分:0)

感谢LarsKotthoff的评论,我发现了错误。

我不得不改变:

var pie = d3.layout.pie()
        .sort(null)
        .value(function (d) {
            return d;
        });

为:

var pie = d3.layout.pie()
        .sort(null)
        .value(function (d) {
            return d.count;
        });

谢谢,祝你有愉快的一天!