最后,我已修复更新这样的功能: http://jsfiddle.net/5ft6uL6k/
我认为是更优雅的方式,使用的地方持有者并更新它们。
基本上这部分:
var bar = chart.selectAll("g").data(data)
bar.enter().append("g").attr("transform", function(d, i) {
return "translate(0," + i * barHeight + ")";
})
var valueBar = bar.append("rect");
valueBar
.attr(valueBarValues.attr)
.attr("width", function(d){return x(d.value)})
.style(valueBarValues.style);
bar.append("text")
.attr(textConfig.attrs)
.style(textConfig.style)
.text(function(d) { return d.name; })
bar.exit().remove();
改变这样的:
var bar = chart.selectAll("g").data(data)
var barEnter = bar.enter().append("g");
barEnter.attr("transform", function(d, i) {
return "translate(0," + i * barHeight + ")";
});
barEnter.append("rect");
barEnter.append("text");
var textBar = bar.selectAll("text")
textBar
.attr(textConfig.attrs)
.style(textConfig.style)
.text(function(d) { return d.name; })
var valueBar = bar.selectAll("rect");
valueBar
.attr(valueBarValues.attr)
.attr("width", function(d){return x(d.value)})
.style(valueBarValues.style);
bar.exit().remove();
你添加文字/每rects徘徊,你应该只拨动它们。看到这里:http://jsfiddle.net/k8sftbez/1/:当你停留在文本上方时,文本看起来更加大胆。它是因为你把文本层放在另一个文本层上每个悬停的另一个文本层 – 2015-04-02 14:24:11
是的,这个问题我是triyng解决 – 2015-04-08 10:18:54