简体   繁体   English

在自定义Power BI visual中包括其他JavaScript库

[英]Including other JavaScript libraries in custom Power BI visual

Could someone please explain how this is done? 有人可以解释一下如何完成吗? I want to use the d3 library but I don't know how to actually use it from within my visual.ts file. 我想使用d3库,但我不知道如何从我的visual.ts文件中实际使用它。 I've installed it with npm and added it to the externalJS part of pbiviz.json, is there anything else I need to configure before I can include and use it in visual.ts? 我已经用npm安装了它,并将其添加到pbiviz.json的externalJS部分,在我可以在visual.ts中包含和使用它之前,还需要配置其他内容吗?

When I add import * as d3 from "../node_modules/d3"; 当我import * as d3 from "../node_modules/d3";添加import * as d3 from "../node_modules/d3"; to the top of visual.ts then I get the following error: 到visual.ts的顶部,然后出现以下错误: 在此处输入图片说明

I've also tried just import * as d3 from "d3" ; 我也尝试过import * as d3 from "d3" to no avail. 无济于事。

I've looked through the source of the example custom visual ( here ) but couldn't actually find any kind of importing/including... In barchart.ts they just start using d3 straight away, which is a bit confusing. 我浏览了示例自定义示例的源代码( 此处 ),但实际上找不到任何类型的导入/包含...在barchart.ts中,它们只是立即开始使用d3,这有点令人困惑。 When I try that I get: 当我尝试时,我得到: 在此处输入图片说明

Could someone please show me what I'm doing wrong? 有人可以告诉我我在做什么错吗?

Did you install typings?: There are draft of docs, how to install typings of d3 library by using npm https://github.com/Microsoft/PowerBI-visuals/pull/186/files 您安装类型了吗?:有文档草稿,如何使用npm https://github.com/Microsoft/PowerBI-visuals/pull/186/files安装d3库的类型

or you can use old way to install typings by using typings utils: https://github.com/Microsoft/PowerBI-visuals/blob/master/Tutorial/Typings.md 或者您可以使用旧的方式通过使用键入实用程序来安装键入: https : //github.com/Microsoft/PowerBI-visuals/blob/master/Tutorial/Typings.md

您需要在pbiviz.json中包含“ externalJS”的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM