2015-04-12 60 views
0

我想在更改x1和x2屬性時更改我的線對象的數據變量的x值。我怎麼做?查看下面的代碼和圖片。更改所選D3對象的數據

function updateBorder(x, whichBorder) { 
    temp_border = svg.selectAll(whichBorder) 
    .attr("x1", x) 
    .attr("x2", x); 
} 

enter image description here

回答

1

您可以修改D3回調您的數據。

function updateBorder(x, whichBorder) { 
    temp_border = svg.selectAll(whichBorder) 
    .each(function (d) { d.x = x }) 
    .attr("x1", x) 
    .attr("x2", x); 
} 

但隨機變異的數據並不總是好主意。