继承人你是新的按钮点击:
$("#next").click(function () {
percent = 17;
var progress = 0;
var timeout = setTimeout(function () {
clearTimeout(timeout);
var randNumber = Math.random() * (100 - 0 + 1) + 0;
//path = path.data(pie(calcPercent(17))); // update the data << change this
path = path.data(pie(calcPercent(randNumber)));
path.transition().duration(duration).attrTween("d", function (a) {
// Store the displayed angles in _current.
// Then, interpolate from _current to the new angles.
// During the transition, _current is updated in-place by d3.interpolate.
var i = d3.interpolate(this._current, a);
var i2 = d3.interpolate(progress, randNumber)
this._current = i(0);
return function(t) {
text.text( format(i2(t) / 100) );
return arc(i(t));
};
}); // redraw the arcs
}, 100);
});
第 8 行的注意事项:
path = path.data(pie(calcPercent(randNumber)));
您需要传递新数据以使其过渡到。我在这里使用了一个随机数,只是为了向您展示任何数字的作品。我为此创建了一个变量并将其传递给“路径”和文本:“i2”> d3.interpolate。
您始终可以将其更改为 17 以适合您的要求:)
更新小提琴:http: //jsfiddle.net/yr595n96/3/