d3.js - 强制有向图

时间:2015-12-07 21:29:47

标签: javascript php json d3.js sparql

我创建了一个PHP脚本,该脚本对SPARQL端点执行查询并将结果放入JSON文件中。到现在为止还挺好。但是,我还需要可视化我在强制有向图中收到的数据。这意味着,如果我理解正确,我需要传递一个JSON文件,指定它们之间的节点和链接,以获得如下图所示的图形(只需复制并粘贴第一行以显示结构):

{
  "nodes":[
    {"name":"Myriel","group":1},
    {"name":"Napoleon","group":1}
   ]
  "links":[
    {"source":1,"target":0,"value":1},
    {"source":2,"target":0,"value":8}
  ]
}

另一方面,从PHP脚本中我收到类似于此的JSON结果:

{"query_type":"select","result":{"rows":[{"name type":"literal","name":"Academy Award","name lang":"en"},{"name type":"literal","name":"Archive","name lang":"en"},{"name type":"literal","name":"Band","name lang":"en"},{"name type":"literal","name":"Band","name lang":"en"},{"name type":"literal","name":"Band","name lang":"en"},{"name type":"literal","name":"Believers","name lang":"en"},{"name type":"literal","name":"Believers","name lang":"en"},{"name type":"literal","name":"Believers","name lang":"en"},{"name type":"literal","name":"Believers","name lang":"en"},{"name type":"literal","name":"Believers","name lang":"en"}],"variables":["name"]},"query_time":0.15745806694031}

所以,我的问题是如何将第二个格式化为第一个(并且处理各种结果,特别是不是这个结果)以便在d3.js中使用结果。非常感谢任何帮助。

0 个答案:

没有答案