javascript - How do I access one field in a JSON file used for force directed? -
i developing forced network based on http://bl.ocks.org/mbostock/4062045#index.html using json file of following format:
{"organizations":[ {"member": {"name":"green 13", "target":"tcan", "category":"community group", "source":"g13"} }, ....
as can see root object "organizations" , top level child object "member". (the json file has in format because generate drupal module.)
i extract member array using code:
var links=members.organizations.map(function(members) { return members.member; });
the network works correctly unable use category attribute set colour of circles.
how access "category" use in "fill" , "name" "text"? (at present, "text" uses "source" value.)
the problem you're not putting category nodes you're generating. so, modify code generates nodes this:
links.foreach(function(link) { link.source = nodes[link.source] || (nodes[link.source] = {name: link.name, category: link.category}); link.target = nodes[link.target] || (nodes[link.target] = {name: link.name, category: link.category}); });
this allow color nodes depending on category , adds correct text. complete example here.
the example doesn't quite work -- names of nodes , source/target strings don't match , messes things up. example, source "g13" doesn't exist (should "green 13"?) , neither "trsg".
Comments
Post a Comment