我不太了解 html、d3js 或 javascript,但根据 Udacity 中的一些类(class),我可以将 d3js 加载到任何网站,在 Web 开发人员控制台中输入此代码:
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://d3js.org/d3.v4.min.js';
document.head.appendChild(script);
看起来非常简单,它适用于我尝试过的每个页面,除了我的 jupyter notebook。该脚本附加在 <head>
中标签,但它的不透明度非常低,当我尝试运行一些 d3js 代码时它不起作用(运行 d3.select("p");
给出 ReferenceError: d3 is not defined
)。还有其他解决方法吗?
最佳答案
这是因为您需要使 d3 全局化。我在牢房里做的就是这个。 Jupyter 已经加载了 require。
%%javascript
require.config({
paths: {
d3: "https://d3js.org/d3.v4.min"
}
});
require(["d3"], function(d3) {
window.d3 = d3;
});
关于javascript - 无法将 d3js 运行到网站(jupyter notebook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44349183/