0
我正在开发堆积图应用程序。d3.js堆积图动画
http://jsfiddle.net/NYEaX/174/
我把它放在一个jQuery插件内创建多个实例等等不同的属性,并最终不同的数据源。
现在我遇到了动画图表栏和轴的问题。
动画条码
animateBars: function(selector, data){
var w = $(selector).data("width");
var h = $(selector).data("height");
var margin = methods.getMargin(h);
methods.setDimensions(w, h, margin);
//methods.setX();
//methods.setY();
//methods.setDomain(data);
var initialHeight = 0;
//var svg = d3.select(selector + " .stackedchart");
var barholder = d3.select(selector + " .barholder");
var state = barholder.selectAll(".state")
.data(data)
.enter()
.append("g")
.attr("class", "g")
.attr("x", function(d) {
return methods.x(d.Label);
})
.attr("transform", function(d) {
return "translate(" + methods.x(d.Label) + ",0)";
});
var bar = state.selectAll("rect")
.data(function(d) {
return d.blocks;
});
// Enter
bar.enter()
.append("rect")
.attr("width", methods.x.rangeBand())
.attr("y", function(d) {
return methods.y(d.y1);
})
.attr("height", function(d) {
return methods.y(d.y0) - methods.y(d.y1);
})
.style("fill", function(d) {
return methods.color(d.name);
});
// Update
bar
.attr("y", function(d) {
return methods.y(d.y1);
})
.attr("height", function(d) {
return methods.y(d.y0) - methods.y(d.y1);
})
.transition()
.duration(500)
.attr("x", function(d) {
return methods.x(d.Label);
})
.attr("width", methods.x.rangeBand())
.attr("y", function(d) {
return methods.y(d.y1);
})
.attr("height", function(d) {
return methods.y(d.y0) - methods.y(d.y1);
});
// Exit
bar.exit()
.transition()
.duration(250)
.attr("y", function(d) {
return methods.y(d.y1);
})
.attr("height", function(d) {
return methods.y(d.y0) - methods.y(d.y1);
})
.remove();
}
它似乎没有任何区别 - http://jsfiddle.net/NYEaX/178/。我还没有看到任何动画叠加图表的例子。我见过一个动画标准条形图的例子,但多数民众赞成在 –
正如我所说,但这是我看到的第一个明显的问题。你的代码同样存在一系列问题。另一个问题是,你要在bar.enter()区域设置bar高度,bar.enter()区域也是在bar更新中设置的,*再次*在转换内部设置。我删除了前两个,并做出了这个:http://jsfiddle.net/XnngU/ – Glenn
那么轴呢。还有一种从头开始砌块的方法。 “对于前者,请将y属性设置为最大高度而不是0: .attr(”y“,methods.height)”http://jsfiddle.net/NYEaX/168/ –