问题
So, I have been trying to import d3 and d3-cloud(for word cloud)
into my AngularJs(v - 1.4) app. I am doing this by -
import d3 from 'd3'
import d3Cloud from 'd3-cloud'.
When I try to use to d3-cloud like d3.layout.cloud() I get the following error
_d2.default.layout.cloud is not a function
回答1:
import { Component, Input, AfterViewInit } from '@angular/core';
// import and assign libs **
import d3 from 'd3'
import * as cloud from 'd3-cloud'
@Component({
selector: 'word-cloud',
templateUrl: './word-cloud.component.html',
styleUrls: ['./word-cloud.component.scss'],
providers: []
})
export class WordCloudComponent implements AfterViewInit {
constructor() { }
ngAfterViewInit() {
d3.scale.category20();
let layout = cloud()
.size([ width , height ])
.words(data)
.rotate(function () ...)
.spiral('rectangular')
.fontSize(function () ...)
.on("end", function () ...)
.start();
}
来源:https://stackoverflow.com/questions/36355842/importing-d3-and-d3-cloud-with-webpack