0

我正在尝试将 susielu/d3-annotation 导入并使用到 Angular 项目中。

    "@types/d3": "^5.7.2",
    "d3": "5.15.0",
    "d3-svg-annotation": "^2.5.1",

这是我的 package.json 的一部分

在组件内部,我可以将 d3 与以下导入一起使用:

import * as d3 from 'd3';

尝试像这样加载注释库:

import * as d3Annotation from 'd3-svg-annotation'

根本不扩展 d3 库,因此我无法访问d3.annotation()方法。

环顾四周,我没有找到解决方案,但我确信这是微不足道的。

4

1 回答 1

0

使用上述导入和以下代码:

const makeAnnotations: any = d3Annotation.annotation()
  .type(d3Annotation.annotationLabel)
  .annotations(annotations)
    
d3.select("#c_boh")
  .append("g")
  .attr("class", "annotation-group")
  .call(makeAnnotations)

它有效,关键是定义任何注释广告,然后.call确实有效

于 2020-08-13T00:00:47.343 回答