【问题标题】:In Angular app, how do I import d3 and use d3.js scripts?在 Angular 应用程序中,如何导入 d3 并使用 d3.js 脚本?
【发布时间】:2020-07-28 09:13:36
【问题描述】:

我在我的 Angular 应用程序中使用 d3.js 版本 3 脚本。

我已经使用命令在 Angular 应用程序中安装了 d3

npm i d3@3

并将 d3 导入为

import * as d3 from 'd3';

即使我如上所述导入了 d3, 我遇到了错误

Property 'layout' does not exist on type 'typeof import("C:/Users/srikar.vodeti/Downloads/imp/dashboardVisual/networkDiagram/node_modules/@types/d3/index")'. 106 var tree = d3.layout.tree()

当我使用 d3.任何方法

提前谢谢..

【问题讨论】:

  • 您遇到了什么错误?你可以在你的问题中添加它吗?
  • 是的,提到了错误

标签: angular d3.js


【解决方案1】:

首先安装 d3 和类型声明

npm install d3 --save
npm install --save @types/d3

然后导入 d3

import * as d3 from 'd3';

如果它不起作用,请告诉我。

【讨论】:

  • 不,它不起作用.. 当我使用 d3.layout.tree() 时出现错误 Property 'layout' does not exist on type 'typeof import("C:/Users/srikar.vodeti/Downloads/imp/dashboardVisual/networkDiagram/node_modules/@types/d3/index")'. 106 var tree = d3.layout.tree()
  • 请创建 stackblitz 演示。所以我可以更好地看它
  • 这里是一个 d3 工作示例,你可以参考这个。 stackblitz.com/edit/d3-svr-sample
  • 你可以使用 var tree = (d3 as any).layout.tree()。那么vs代码就不会报错了
  • 完成上述步骤后..得到以下错误并最终能够解决...stackoverflow.com/questions/56400413/…
猜你喜欢
  • 2017-02-08
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
  • 2016-01-27
  • 1970-01-01
  • 1970-01-01
  • 2019-04-23
  • 1970-01-01
相关资源
最近更新 更多