d3js tree.nodes()不是函数

时间:2016-12-11 15:04:11

标签: d3.js

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

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

未捕获TypeError:tree.nodes不是函数

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

1 个答案:

答案 0 :(得分:8)

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()
相关问题