简体   繁体   English

d3js 导入到 angular2

[英]d3js importing to angular2

How can I import d3js int angular2 project?如何导入d3js int angular2 项目? I installed the d3js using npm and added d3js to my systemJs however its giving me traceur.js error.我使用 npm 安装了 d3js 并将 d3js 添加到我的 systemJs 但是它给了我traceur.js错误。 I also tried just using latest cdn in script and did import * as d3 from 'd3';我还尝试在脚本中使用最新的 cdn 并import * as d3 from 'd3'; but that can't find the module.但是找不到模块。

SystemConfig.js,this setup gives me traceur.js error SystemConfig.js,这个设置给了我 traceur.js 错误

var map = {
    'd3': 'node_modules/d3'
  };

var packages = {
    'd3': {main: 'index.js'},
  };

I ran into the same error when importing d3.我在导入 d3 时遇到了同样的错误。 If you installed d3 using es6 module like I did then setting the path to the bundle file will get rid of the error.如果您像我一样使用 es6 模块安装 d3,那么设置包文件的路径将消除错误。

var map = {
  'd3': 'node_modules/d3/build'
};

var packages = {
  'd3': {main: 'index.js'},
};

After this you should be able to us d3 in the following way.在此之后,您应该可以通过以下方式访问我们的 d3。

import d3 from 'd3';

I used the following page to help me figure this out.我使用以下页面来帮助我解决这个问题。 https://github.com/d3/d3/issues/2900 https://github.com/d3/d3/issues/2900

You could still use import * as d3 from 'd3';你仍然可以使用import * as d3 from 'd3';

but import '@types/d3' into your devDependencies.但是将'@types/d3'导入到您的 devDependencies 中。 After you did this, you would be able to get the modules.完成此操作后,您将能够获取模块。 I use this in my ng5 application.我在我的 ng5 应用程序中使用它。

Perform this step 1) move to the angular project folder run this on the terminal执行此步骤 1) 移至 angular 项目文件夹,在终端上运行此步骤

 npm i d3

2) from your component class use the following import statement. 2) 从您的组件类使用以下导入语句。

import * as d3 from "d3";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM