简体   繁体   English

更新多个甜甜圈图d3.js的大小和值

[英]Update size and value of multiple donut charts d3.js

i'm working on a project using JS and d3.js 3.x. 我正在使用JS和d3.js 3.x进行项目。

I've a force layout where every node is sorrounded by a donut chart. 我有一个强制布局,其中的每个节点都被一个甜甜圈图包围。

Now I'm trying to update the data and resize nodes and donut charts with a transition but I'm having big troubles with the arcTween function. 现在,我试图通过过渡来更新数据并调整节点和甜甜圈图的大小,但是在使用arcTween函数时遇到了很多麻烦。

If I create arc variable not depending by data, the arcTween function does what it should do but it does not if I set outer and inner radius like this: 如果创建不依赖数据的弧形变量,则arcTween函数会执行应做的事情,但是如果我这样设置外半径和内半径,则不会这样做:

    var arc = d3.svg.arc()
    .innerRadius(function(d){
        if(d.data.group==1)
            return radiusScale(d.data.value);
    })
    .outerRadius(function(d){
        if(d.data.group==1)
            return radiusScale(d.data.value)+10;
    })
    .cornerRadius(11);

I've tried many solutions but none of them works. 我已经尝试了许多解决方案,但没有一个可行。

Here the Fiddle with the full code: https://jsfiddle.net/56n4fhLg/1/ 这里是带有完整代码的小提琴: https : //jsfiddle.net/56n4fhLg/1/

Thanks 谢谢

I've found the problem, I forgot to save the "d" for each pathPie: 我发现了问题,我忘了为每个pathPie保存“ d”:

    pathPie
    .attr("id", function(d,i) { return "arc_"+d.data.target; })
    .attr("d", function(d, i) {
            var temp = radiusScale(d.data.value);
            arc.innerRadius(temp)(d, i);
            temp += 10;
            return arc.outerRadius(temp)(d, i);
    })
    .each(function(d) {
        this._current = d;
    });

Here the code updated: https://jsbin.com/yosesotuwo/edit?output 此处代码已更新: https : //jsbin.com/yosesotuwo/edit?output

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM