【发布时间】:2014-04-08 19:04:57
【问题描述】:
我正在用d3.js 绘制饼图。我想在添加新数据时转换饼图。 (我正在使用可重复使用的图表 API)。我首先使用 enter 创建一个图表组,然后将图表弧路径附加到该组:
var arcGroup = svg.select(".pie").selectAll(".arc " + selector)
.data(pie(data))
.enter().append("g")
.attr("class", "arc " + selector);
if (options.left) {
arcGroup.attr('transform', 'translate(' + options.left + ',' + options.top + ')');
} else {
arcGroup.attr('transform', 'translate(' + options.width / 2 + ',' + options.height / 2 + ')');
}
//append an arc path to each group
arcGroup.append("path")
.attr("d", arc)
//want to add the transition in here somewhere
.attr("class", function (d) { return 'slice-' + d.data.type; })
.style("fill", function (d, i) {
return color(d.data.amount)
});
//...
问题是当新数据进入时,我需要能够转换路径(以及小提琴中显示的文本节点),但输入选择是在父组上进行的。如何添加 transition() 使其适用于路径?
【问题讨论】:
标签: javascript d3.js