1

currently i am doing is represent relation ships of data using d3.js. need to represent it in a tree. My data stored at Neo4j server. And application is design under Express frame work.

var cypher = [
                "match (b:Binary)-[r*..1]->(a:Binary)",
                    "where a.Key = '" + data + "'",
                "return collect( distinct b) as dep"].join("\n");

execute this query and put the result in to a queue and sequentially execute it. this is for getting all children of the node. But I need to make this not as flat json something like depth. like `

{
 "name": "flare",
 "children": [
  {
   "name": "analytics",
   "children": [
    {
     "name": "cluster",
     "children": [
      {"name": "AgglomerativeCluster", "size": 3938},
      {"name": "CommunityStructure", "size": 3812},
      {"name": "HierarchicalCluster", "size": 6714},
      {"name": "MergeEdge", "size": 743}
     ]
    },
......  how can i do it?
Prathibha Chiranthana
  • 822
  • 1
  • 10
  • 28
  • 1
    I guess you're using the REST API for this: get the response you receive from the query and build your own JS object to map the structure above. Then just stringify it in JSON. And please, use the `params` structure to send the data: it's not nice to have Cypher injections http://docs.neo4j.org/chunked/stable/rest-api-cypher.html#rest-api-use-parameters – MarcoL Aug 13 '14 at 12:01
  • no I use a npm library Node-neo4j. – Prathibha Chiranthana Aug 14 '14 at 04:07

2 Answers2

2

You should use d3's nest function to do this. This is actually mostly a JSON question, it seems your problem is that you need to start with the JSON output that the RESTful services Neo4J provides, and then transform that into a JSON structure suitable for tree representation in D3. The nest function will really help with that.

A second option you have is to use a tool like json2json, which is a more generic tool intended to help transform from one json structure into another. Under that approach, you write a set of template rules and then translate a data structure.

FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86
1

don't make down votes. i think you can have this answer chiran.

Generate (multilevel) flare.json data format from flat json

Community
  • 1
  • 1