简体   繁体   English

无法使D3粒子示例正常工作?

[英]Can't get D3 particles example to work?

I'm looking at Mike Bostock's particles example for D3.js. 我正在看Mike Bostock的D3.js 粒子示例

I have copied and pasted the code locally, without changing anything at all. 我已经在本地复制并粘贴了代码,根本没有做任何更改。 I'm running the code using SimpleHTTPServer, so there shouldn't be any security issues to do with running locally. 我正在使用SimpleHTTPServer运行代码,因此在本地运行应该不会有任何安全性问题。

Whenever I mouseover the body, I see the following error in the console: 每当我将鼠标悬停在主体上时,在控制台中都会看到以下错误:

Uncaught TypeError: Object #<Object> has no method 'mouse' 

Does anyone know what might be going on? 有人知道会发生什么吗? Can anyone get it to work locally? 谁能在本地工作?

Thanks. 谢谢。

Did you actually hardcopied the entire referenced library? 您是否真的复制了整个参考图书馆? It could be an inter-domain referencing issue. 这可能是域间引用问题。 Did you do a reference directly to http://mbostock.github.com/d3/d3.js?1.25.0 ? 您是否直接参考了http://mbostock.github.com/d3/d3.js?1.25.0 it could be, that this is not possible from outside that domain. 可能是,从该域之外无法做到这一点。

There's a way to fix the code, so that you can reference the latest release of D3 at http://d3js.org/d3.v3.min.js 有一种方法可以修复代码,以便您可以在http://d3js.org/d3.v3.min.js上引用最新版本的D3。

The error you're getting is caused by the line var m = d3.svg.mouse(this); 您收到的错误是由以下行引起的:var m = d3.svg.mouse(this); Change it to var m = d3.mouse(this); 将其更改为var m = d3.mouse(this); and you should be fine. 你应该没事的

See the release notes here, on the changes from D3 v2 to v3: https://github.com/mbostock/d3/wiki/Upgrading-to-3.0 有关从D3 v2到v3的更改,请参阅此处的发行说明: https : //github.com/mbostock/d3/wiki/Upgrading-to-3.0

Specifically: 特别:

"SVG: The aliases d3.svg.mouse and d3.svg.touches have been removed; use d3.mouse and d3.touches instead. These methods are identical, and were moved in an earlier minor release that added support for HTML as well as SVG elements." “ SVG:别名d3.svg.mouse和d3.svg.touches已被删除;改用d3.mouse和d3.touches。这些方法是相同的,并且在较早的次要版本中已移动,该版本也增加了对HTML的支持作为SVG元素。”

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

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