javascript - 如何更改 D3.js 中路径的颜色?

标签 javascript d3.js

我正在 D3 的 TreeMap 中创建一些路径,我想更改线条(路径)的颜色,但我无法使我的代码工作:

 // Enter any new links at the parent's previous position.
      link.enter().insert("svg:path", "g")
          .attr("class", "link")
          .attr("d", function(d) {
            var o = {x: source.x0, y: source.y0};
            return diagonal({source: o, target: o});
          })
        .transition()
          .duration(duration)
          .attr("d", diagonal);

      // Transition links to their new position.
      link.transition()
          .duration(duration)
          .attr("d", diagonal);

      // Transition exiting nodes to the parent's new position.
      link.exit().transition()
          .duration(duration)
          .attr("d", function(d) {
            var o = {x: source.x, y: source.y};
            return diagonal({source: o, target: o});
          })
          .remove();

我尝试使用以下内容进行更改,并且查找了一些其他解决方案,但我无法真正理解我需要在更新选择中选择什么来更改它。

  link.selectAll("path")
      .attr("stroke", "#000000");

感谢您提前提供的帮助。

最佳答案

我自己刚开始使用 d3,但我认为你需要使用 link.style("lines",#xxxxxx)。

关于javascript - 如何更改 D3.js 中路径的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23632848/

相关文章:

javascript - 隐藏在模态后面的 jQueryUI 自动完成功能

javascript - 从 UpdatePanel 更新 JavaScript 变量

javascript - 用JS检测后退和前进按钮

javascript - 使用 D3.js 在矩形上显示文本

javascript - d3 force layout固定节点之间的链接

javascript - 交互式饼图 : Associate a click event with a slice of a pie chart

javascript - 用于打印功能的 jquery 在 asp.net 中不起作用

javascript - 为什么在文本更改事件后滚动 "Up"? (奇怪的 Action )

javascript - 将 'onclick' 事件附加到 D3 图表背景

javascript - HTMLcollection 0 列表长度,[n]返回undefined,转换为数组返回空数组