更改所选 D3 对象的数据
Changing data for selected D3 object
我想在更改 x1 和 x2 属性的同时更改线对象数据变量中的 x 值。我怎么做?请参阅下面的代码和图片。
function updateBorder(x, whichBorder) {
temp_border = svg.selectAll(whichBorder)
.attr("x1", x)
.attr("x2", x);
}
您可以在 d3 回调中修改您的数据。
function updateBorder(x, whichBorder) {
temp_border = svg.selectAll(whichBorder)
.each(function (d) { d.x = x })
.attr("x1", x)
.attr("x2", x);
}
但是在随机位置改变数据并不总是好主意。
我想在更改 x1 和 x2 属性的同时更改线对象数据变量中的 x 值。我怎么做?请参阅下面的代码和图片。
function updateBorder(x, whichBorder) {
temp_border = svg.selectAll(whichBorder)
.attr("x1", x)
.attr("x2", x);
}
您可以在 d3 回调中修改您的数据。
function updateBorder(x, whichBorder) {
temp_border = svg.selectAll(whichBorder)
.each(function (d) { d.x = x })
.attr("x1", x)
.attr("x2", x);
}
但是在随机位置改变数据并不总是好主意。