d3js tree.nodes()不是函数 [英] d3js tree.nodes() is not a function

查看:628
本文介绍了d3js tree.nodes()不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

While the below piece of code works find in d3v3, it fails in v4.

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

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

Uncaught TypeError: tree.nodes is not a function

在v4中有什么替代方案?

What is the alternative for it in 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()

这篇关于d3js tree.nodes()不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆