d3.js - 为 Power BI 自定义视觉开发安装 d3 Typings 时遇到问题

标签 d3.js powerbi typescript-typings

我在安装 d3 类型时遇到问题。我按照 Microsoft 的说明进行操作:https://github.com/Microsoft/PowerBI-visuals/blob/master/Tutorial/Typings.md以及 Sachin Patney 在他的视频 https://www.youtube.com/watch?v=_2-yMGtEv2w 中所做的事情.

运行“npm installtypings -g”似乎工作正常。

运行“typings install --save --global dt~d3”或“typings i dt~d3 -G”都会产生此错误:“typings ERR!消息尝试将“d3”编译为全局模块,但它看起来像一个外部模块。您需要删除全局选项才能继续。”

如果我删除全局选项,它会使用路径中的“modules”文件夹而不是“globals”文件夹在我的视觉文件夹中添加类型信息(即 MyVisual|typings|modules|d3 而不是 MyVisual|typings |全局变量|d3)。 Intellisense 也不适用于 d3。

知道为什么我无法全局安装 d3 类型吗?

最佳答案

尽管 @FabioEnne 的回答确实解决了我有关全局安装和智能感知的问题,但我仍然遇到了与该问题的最初原因相关的其他问题。但我想我找到了解决办法......

根据乔恩·加兰特的说法:

The Power BI team just released v1.2 of the Custom Visuals SDK. With this version you now need to reference d3 v3.5.5 yourself. d3 v4 does not work yet. I’m working with the team to get a v4 compat and sample together, but for now you can only use v3.5.5.

(@FabioEnne 的解决方案将 v4.4.0 添加到我的系统中。)

Jon 在他的网站上提供了此问题的解决方案:http://blog.jongallant.com/2016/11/pbiviz-12-d3-35-reference/ 。 (他附上了一段视频。)

乔恩解决方案的要点是:

安装类型:

npm i -g typings

添加 d3 v3.5.5:

npm i d3@3.5.5 --save

添加 d3 输入:

typings install d3=github:DefinitelyTyped/DefinitelyTyped/d3/d3.d.ts#6e2f2280ef16ef277049d0ce8583af167d586c59 --global --save

将文件添加到 tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES5",
    "sourceMap": true,
    "out": "./.tmp/build/visual.js"
  },
  "files": [
    ".api/v1.3.0/PowerBI-visuals.d.ts",
    "typings/index.d.ts",
    "node_modules/d3/d3.min.js",
    "src/visual.ts"
  ]
}

关于d3.js - 为 Power BI 自定义视觉开发安装 d3 Typings 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41470138/

相关文章:

javascript - 使用 d3.js 向饼图添加文本标签时遇到问题

javascript - 通过 PowerBI API 在嵌入 View 中创建报告

Excel数据模型: Return last non blank

typescript - Typescript能够执行简单的功能组合吗?

angular - 使用自己的类型发布 angular 包 - 类型引用包含错误的路径

typescript - Typescript 中的 'declare global' 是什么?

javascript - 需要帮助修改 d3.js Collapsible Force Layout

javascript - 数据图 - 根据值更改颜色

azure - 无法将排放影响仪表板连接到 Azure

d3.js - 如何更新 D3 中的特定节点