我已經創建了具有一定價值的文本節點。所以無論何時數據更新,只有值應該更新,不應該再次創建文本節點。D3如何更新文字?
systemLevel
.enter()
.append('g')
.classed("system-level", true)
.attr("depth", function(d, i) {
return i;
})
.each(function(d, i) {
var columnHeader = graphHeaders.append("g")
.classed("system-column-header", true);
columnHeader.append('text')
.attr('font-size', '14')
.attr('font-weight', 'bold')
.attr('fill', "red")
.attr('x', 50 * i)
.attr('y', 50)
.text(function() {
return d.newUser;
});
columnHeader.append('text')
.attr('font-size', '14')
.attr('font-weight', 'bold')
.attr('fill', "blue")
.attr('x', 50* i)
.attr('y', 70)
.text(function() {
return d.value;
});
});
我在Js Bin上創建了一個示例。 https://jsbin.com/dixeqe/edit?js,output
我不確定如何更新文本值。任何幫助表示讚賞!
那究竟是什麼問題呢? D3更新模式在許多教程中都有介紹,例如http://bost.ocks.org/mike/circles/ –
我已經提到了很多關於更新的教程,但仍然無法在這個特定場景中使用它。 – user2532865