“import”ing d3 and d3-cloud with webpack

可紊 提交于 2019-12-10 18:06:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!