2017-09-01 54 views
0

性質d3js我試圖用使用下面的命令angular2 蔭d3.js在Angular2着訪問像`d3.svg(),d3.scale()`和其他一些與angular2

安裝D3
npm install --save d3 
install --save-dev @types/d3 

的package.json樣子

{ 
    "name": "my-app", 
    "version": "0.0.0", 
    "license": "MIT", 
    "scripts": { 
    "ng": "ng", 
    "start": "ng serve", 
    "build": "ng build", 
    "test": "ng test", 
    "lint": "ng lint", 
    "e2e": "ng e2e" 
    }, 
    "private": true, 
    "dependencies": { 
    "@angular/animations": "^4.0.0", 
    "@angular/common": "^4.0.0", 
    "@angular/compiler": "^4.0.0", 
    "@angular/core": "^4.0.0", 
    "@angular/forms": "^4.0.0", 
    "@angular/http": "^4.0.0", 
    "@angular/platform-browser": "^4.0.0", 
    "@angular/platform-browser-dynamic": "^4.0.0", 
    "@angular/router": "^4.0.0", 
    "core-js": "^2.4.1", 
    "d3": "^4.10.0", 
    "rxjs": "^5.1.0", 
    "zone.js": "^0.8.4" 
    }, 
    "devDependencies": { 
    "@angular/cli": "1.2.1", 
    "@angular/compiler-cli": "^4.0.0", 
    "@angular/language-service": "^4.0.0", 
    "@types/d3": "^4.10.0", 
    "@types/jasmine": "~2.5.53", 
    "@types/jasminewd2": "~2.0.2", 
    "@types/node": "~6.0.60", 
    "codelyzer": "~3.0.1", 
    "jasmine-core": "~2.6.2", 
    "jasmine-spec-reporter": "~4.1.0", 
    "karma": "~1.7.0", 
    "karma-chrome-launcher": "~2.1.1", 
    "karma-cli": "~1.0.1", 
    "karma-coverage-istanbul-reporter": "^1.2.1", 
    "karma-jasmine": "~1.1.0", 
    "karma-jasmine-html-reporter": "^0.2.2", 
    "protractor": "~5.1.2", 
    "ts-node": "~3.0.4", 
    "tslint": "~5.3.2", 
    "typescript": "~2.3.3" 
    } 
} 

,我添加路徑.angular-cli.json

一些我不能一個屬性像d3.svg(), d3.scale()和其他一些其他

它返回錯誤。

可能是什麼原因?

+1

您不應該更新'.angular-cli.json'文件。我有一個工作[github](https://github.com/PdUi/ng-d3v4-components/tree/ng-bubble-latest)回購,展示瞭如何在角度上使用d3。在這裏回答你的問題是非常困難的,因爲不清楚哪裏出了問題以及你嘗試了什麼。你在哪裏試圖使用這些功能(包括代碼),你正在得到什麼錯誤?另外,你什麼時候收到錯誤? – peinearydevelopment

+1

['scale'和'svg'可能在「node \ _modules/@ types/d3/index」]中不存在(https://stackoverflow.com/questions/40988732/scale-and-svg-does-未存在-在節點模塊類型-D3-指數) – altocumulus

回答

0

您可以從d3導入具體的方法,就像rxjs操作符一樣。

import { scaleLinear } from 'd3-scale'; 

您可以使用該方法無需D3命名空間:

var x = scaleLinear(); 

或者,你可以導入所有

import * as d3 from "d3"; 

var x = d3.scaleLinear(); 

注意,存在d3.v4

沒有形成規模