javascript - Accessing JSON values in D3 -



javascript - Accessing JSON values in D3 -

i'm trying populate each grouping circle "forehand" / "backhand" , "bh slice" i'm having difficulties accessing these values. have nested elements in way "direction" key related values influence position , size of each circle.

in way similar https://github.com/mbostock/d3/wiki/selections#data matrix illustration guess info construction different ?

jsbin of current code here: http://jsbin.com/gahul/1

i have next data:

var jsondata = [ { "direction": "crosscourt", "total": 118, "forehand": 75, "backhand": 41, "bh slice": 2 }, { "direction": "down_middle", "total": 50, "forehand": 34, "backhand": 9, "bh slice": 7 }, { "direction": "down_line", "total": 21, "forehand": 8, "backhand": 11, "bh slice": 2 }, { "direction": "inside_out", "total": 118, "forehand": 25, "backhand": 5, "bh slice": 0 }, { "direction": "inside_in", "total": 9, "forehand": 9, "backhand": 0, "bh slice": 0 }, ];

and next d3 code:

var query1 = d3.nest() .key(function(d){ homecoming d.direction; }) .sortkeys(d3.ascending) .entries(jsondata) var h = 420; var w = 500; var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); var grouping = svg.selectall("g") .data(query1) .enter() .append("g") .attr("class", function(d){ homecoming d.key }) var pop_directions = group.selectall("circle") .data(query1) .enter() .append("circle") .attr("r", 30 ) .attr("cx", 100)

the values of new object in array 1 element, have adress, instance:

d.values[0].forehand

gives forehand-value, while can access key-value by

d.key

see http://jsbin.com/hakamoga/1/edit simple illustration using forehand-value radius , title.

javascript json d3.js

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -