을 내가 drewmoore의 suggestiong EIT에 대해 확실하지 않다 그녀. 그것은 나를 위해 일하는 것 같지 않았다.
두 가지 제안을 계속했습니다.
우수 답변
첫 번째는 알로의 대답에 대한 추가 사항입니다. 원래이 주석을 썼을 때, 나는 알로의 답변을 얻을 수 없었습니다. 이제 나는 그 이유를 이해했다. d3 계층 패키지를 사용하려고했습니다.
npm install d3 --save
npm install @types/d3 --save-dev
npm install @types/d3-hierarchy --save-dev
을 그리고 모듈이 방법을 사용하여 : : 그래서 설치
import * as d3 from "d3";
d3.hierarchy(blah);
을 그리고 그것은이 d3.hierarchy 회원에 대해 알고하지 않았다 불평 것입니다. 이제 나는 그 객체를 사용해야 만한다는 것을 이해한다. (내가 전에 등록하지 않은 이유를 모른다.) 그래서, 업데이트 :
import * as d3 from "d3";
import * as d3Hierarchy from "d3-hierarchy";
d3Hierarchy.hierarchy(blah);
원래 대답 지금까지 링크에있는 d3-ng2-service 모듈을 사용하고있는 것으로 나타났습니다 유일한 해답이 될 것으로 보인다 무엇
. 훌륭한 스위치는 아니지만 각도 2 프로젝트에서 d3v4를 사용할 수 있습니다.
추가 정보에서 발췌는 각 2 구성 요소에서 사용하는 방법의 아래에서 발견 할 수 있습니다
import { Component, OnInit, ElementRef } from '@angular/core';
import { D3Service, D3, Selection } from 'd3-ng2-service'; // <-- import the D3 Service, the type alias for the d3 variable and the Selection interface
@Component({
selector: 'app-test-d3',
templateUrl: 'test-d3.component.html',
styleUrls: ['test-d33.component.css']
})
export class TestD3Component implements OnInit {
private d3: D3; // <-- Define the private member which will hold the d3 reference
private parentNativeElement: any;
constructor(element: ElementRef, d3Service: D3Service) { // <-- pass the D3 Service into the constructor
this.d3 = d3Service.getD3(); // <-- obtain the d3 object from the D3 Service
this.parentNativeElement = element.nativeElement;
}
ngOnInit() {
let d3 = this.d3; // <-- for convenience use a block scope variable
let d3ParentElement: Selection<any, any, any, any>; // <-- Use the Selection interface (very basic here for illustration only)
// ...
if (this.parentNativeElement !== null) {
d3ParentElement = d3.select(this.parentNativeElement); // <-- use the D3 select method
// Do more D3 things
}
}
}
현재로서는 길을 찾지 못했기 때문에, Any 유형의 d3v4 객체를 정의한 후 메리 터로갔습니다. 그들이 끝나면 온보드를 가져올 것입니다. 그러나 방법이 있다면, 나는 또한 알고 싶습니다. –
정확히 어떻게 했습니까? 나는 현재 'd3'에서 D3으로 가져 오기 *를 가지고 있지만'd3 '에서 가져온 것 :'d3 '에서 가져온 것;은 작동하지 않는다 ... – TommyF
d3을 자체 스크립트 요소로 페이지에로드 한 다음 잡는다. 내 컨트롤러에서 확장 된 angular.IWindowService를 사용하면'd3 : any' 속성 만 추가됩니다. –