【问题标题】:Changing data for selected D3 object更改选定 D3 对象的数据
【发布时间】:2015-04-13 02:37:24
【问题描述】:

我想在更改 x1 和 x2 属性时更改我的线对象的数据变量中的 x 值。我怎么做?请参阅下面的代码和图像。

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

【问题讨论】:

    标签: d3.js


    【解决方案1】:

    您可以在 d3 回调中修改数据。

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

    但在随机位置改变数据并不总是好主意。

    【讨论】:

      猜你喜欢
      • 2016-10-29
      • 2019-05-15
      • 2010-10-24
      • 1970-01-01
      • 2015-05-28
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 2014-08-05
      相关资源
      最近更新 更多