在D3中收集网络图的一些数据。我该如何格式化?

时间:2016-04-04 14:43:06

标签: javascript d3.js graph

我正在使用D3 JavaScript库收集数据以创建网络图。

使用的最佳格式是什么?我的想法是一个带有架构的数据库

Source Node, Relation, Destination Node

此处还应考虑其他因素吗?

我想要的只是展示人与人之间的简单关系。假设我想在facebook上描绘每个人都是一个地理区域的朋友(仅举例)。

所以我们假设我有一个伦敦人的数据集。

所以,如果我收集了源人ID,他们与另一个人的关系(“朋友”或“订阅”),以及另一个人的身份证,那么我可以使用D3以图形方式显示,是吗?

这是收集数据的理想方式吗?

我已经尝试过查看D3手册了,但对我来说并非100%清楚。

感谢。

1 个答案:

答案 0 :(得分:1)

Have a look at the sample data at the bottom of this example: https://bl.ocks.org/mbostock/4062045. When using d3's force layout, you'll need two arrays: one listing the nodes, and one listing the links. The "group" and "value" variables are specific to this example (i.e. not required), although in your case the relationship you mention could be substituted for "value". So you're database table would match well with the "links" array and you could then construct the nodes array from that.