javascript - How can I update text-label in d3 donut according with my array's data -
i trying add percentage instead of labels here according array. need label updated after every donut's transition. if insert .text(function (d) { return d.data.value;});
shows me second array's value , doesn't change. how can fix it?
ps: saw similar questions here - cant intergate solution donut.
update label on end of transition:
slice .transition().duration(1000) .each("end", function(d,i){ d3.selectall('.labels text') .text(function(d) { return (((d.endangle - d.startangle) / (2 * math.pi)) * 100).tofixed(0) + '%'; }) }) .attrtween("d", function(d) { this._current = this._current || d; var interpolate = d3.interpolate(this._current, d); this._current = interpolate(0); return function(t) { return arc(interpolate(t)); }; });
updated example.
Comments
Post a Comment