d3.js - d3js tree.nodes() 不是函数

标签 d3.js

虽然下面的代码可以在 d3v3 中找到,但在 v4 中却失败了。

 var nodes = tree.nodes(root).reverse(),
      links = tree.links(nodes);

Uncaught TypeError: tree.nodes is not a function



在 v4 中它的替代方案是什么?

最佳答案

import { hierarchy, tree } from 'd3-hierarchy'

// create a hierarchy from the root
const treeRoot = hierarchy(root)
tree(treeRoot)
// nodes
const nodes = treeRoot.descendants()
// links
const links = treeRoot.links()

关于d3.js - d3js tree.nodes() 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41087568/

相关文章:

javascript - 在 C3 图表中设置范围属性

javascript - 使用 d3 和 d3.tip 计算 div 元素的坐标

javascript - d3.event 在组合模块时不起作用

typescript 折线图 d3

d3.js - D3 - 刷子和刷子 handle 的编程控制

html - 创建无限平行模式

javascript - 禁用图例单击 NVD3 多图

javascript - 链接两个 D3 图

svg - 在缩放平移后检测 d3.js 强制布局中的可见节点

d3.js - 水平滚动的 C3/D3 条形图