【问题标题】:How to fix ".join is not a function" when trying join after selectAll?在 selectAll 后尝试加入时如何解决“.join 不是函数”?
【发布时间】:2020-06-09 12:45:06
【问题描述】:

我正在尝试使用此示例绘制可缩放 SUnburst 图表:https://vizhub.com/undefined/7babe7cceb394cd1bc93157a29f8c161

代码在普通 js 中运行,但是当我尝试在 Angular 中导入它时,它会抛出以下错误:

ERROR TypeError: "svg.selectAll(...).data(...).join 不是函数"

抛线错误是:

const path = svg.selectAll('path')
      .data(root.descendants().slice(1))
      .join('path')
      .attr('fill', d => {
        while (d.depth > 1) { d = d.parent; }
        return color(d.data.name);
      })
      .attr('fill-opacity', d => arcVisible(d.current) ? (d.children ? 0.6 : 0.4) : 0)
      .attr('d', d => arc(d.current));

我尝试将类添加到 svg 元素,但没有帮助。删除它不会呈现图形,并且每个连接都会引发错误。此外,更新到最新的 d3,但它没有帮助 Angular 版本是 6。

控制台日志

g.append('g')
 .selectAll('path')
 .data(root.descendants().slice(1))

【问题讨论】:

标签: angular d3.js


【解决方案1】:

join('path') 替换为enter().append('path')

【讨论】:

  • 我从 vanilla JS 到 Angular/TypeScript 时遇到了同样的问题。你知道为什么 Angular/TypeSscript 中没有定义 join 吗?
【解决方案2】:

我遇到了同样的问题。我通过升级到最新的 d3 版本(从 5.x 到 5.16)来修复它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 2019-05-19
    • 2019-10-31
    • 2020-06-21
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多