如何将从Neo4j导出的JSON文件导入D3

时间:2014-06-21 06:19:06

标签: json d3.js import neo4j export

Neo4j是一个图形数据库,它可以将数据导出到JSON文件。但是,来自Neo4j的JSON文件在某种程度上对我来说非常复杂,我无法将其导入D3。我的问题是如何从Neo4j导入JSON文件并将其导入D3以进行图形可视化,而无需更改JSON文件的格式。我曾经问过Neo4j社区,他们说这是不可能的,或者我认为他们的意思是。

以下是Neo4j导出的JSON文件:

{
 "table":
    {
      "_response":
        {
         "columns":["n"],
         "data":[
             {"row":[{"num":"A08"}],"graph":{"nodes":[{"id":"0","labels":["Person"],"properties":{"num":"A08"}}],"relationships":[]}},
             {"row":[{"num":"A04"}],"graph":{"nodes":[{"id":"1","labels":["Person"],"properties":{"num":"A04"}}],"relationships":[]}},
             {"row":[{"num":"A05"}],"graph":{"nodes":[{"id":"2","labels":["Person"],"properties":{"num":"A05"}}],"relationships":[]}}
            ],
         "stats":{
              "contains_updates":false,"nodes_created":0,"nodes_deleted":0,"properties_set":0,"relationships_created":0,"relationship_deleted":0,
              "labels_added":0,"labels_removed":0,"indexes_added":0,"indexes_removed":0,"constraints_added":0,"constraints_removed":0
             }
        },
     "nodes":[
          {"id":"0","labels":["Person"],"properties":{"num":"A08"}},
          {"id":"1","labels":["Person"],"properties":{"num":"A04"}},
          {"id":"2","labels":["Person"],"properties":{"num":"A05"}}
         ],
     "other":[],
     "relationships":[],
     "size":3,
     "stats":{
          "contains_updates":false,"nodes_created":0,"nodes_deleted":0,"properties_set":0,"relationships_created":0,"relationship_deleted":0,
          "labels_added":0,"labels_removed":0,"indexes_added":0,"indexes_removed":0,"constraints_added":0,"constraints_removed":0
         }
    },
 "graph":
     {
          "nodeMap":{
             "0":{"num":"A08"},
             "1":{"num":"A04"},
             "2":{"num":"A05"}
            },
      "relationshipMap":{
                 "623":{"date":"5/01/2011","time":"18:11:48","case":4},
                 "624":{"date":"5/02/2011","time":"21:21:06","case":4},
                 "625":{"date":"6/03/2011","time":"21:23:35","case":4},
                 "629":{"date":"6/04/2011","time":"22:14:47","case":5}
                }
     }
}

我使用的D3是http://bl.ocks.org/mbostock/1153292

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用literal maps自定义Cypher返回的输出。使用它应该可以准确地返回要交给D3的json结构。

另一种方法是使用一些应用程序端json转换,例如参见http://maxdemarzi.com/2012/10/11/hubway-data-visualization-challenge-with-neo4j/