NaN on Force-Directed Layout Append in D3.js

谁说我不能喝 提交于 2019-12-09 23:36:10

问题


I'm using a force-directed layout in D3 that grabs data from a JSON file and then, when one of the nodes is double-clicked, queries the database to find links to that node and updates the links and nodes arrays attempting to append the new data to the viz. It seems when the nodes are appended without links, they work fine, but the links to the xy coordinates end up being NaN. You can see the effect here, just double-click on one of the nodes:

http://blockses.appspot.com/2432083


回答1:


I fixed this by rewriting the code to follow the force-directed with append example from Bostock. The problem seems to occur when you overwrite your nodes and links arrays rather than pushing data to them, in case anyone runs into similar issues.

The updated code is in the original gist and can be seen here:

http://blockses.appspot.com/2432083




回答2:


Old post, but I also hit this issue and my solution was different.

I figured out when I was setting the size of the force layout :

networkViewerVariables.force = d3.layout.force()
        .gravity(.05)
        .distance(50)
        .charge(-50)
        .size([forceWidth, forceHeight])

The 'forceWidth' and 'forceHeight' variables were null. When I populated these, the errors were gone.

Hope that helps someone :)



来源:https://stackoverflow.com/questions/10273981/nan-on-force-directed-layout-append-in-d3-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!