javascript - Best way to format a JSON for D3 Forced Directed -
i'm using neo4j graph db hold data network traffic pcap. i'm able perform queries, , resulting json, having hard time finding easy way format json node: link: format needed d3's force directed graph!
any appreciated, can't seem find links json formatting portion of creating d3 graph.
the force layout expects 2 arrays: array of objects nodes, can have whatever attributes, , array of links, objects need have .source , .target attribute point array position of nodes link. whatever export should array of json objects nodes , use kind of hash translate id values of source , target array position of objects in array.
so if you've got:
nodes = [{name:"nodea"},{name:"nodeb"},name:"nodec"]
..then link in link array between 2 this:
links = [{name: "linka", source: 0, target: 1}, {name: "linkb", source: 2, target: 0}]
note it's pointing x of nodes[x] of node object, , not arbitrary id value. first link connects nodea , nodeb, while second connects nodec , nodea. when export nodes, need keep track of array position edges.
Comments
Post a Comment