arrays - How to access nested data Values in D3 -
i have nested data this
var nested_data = d3.nest() .key(function(d) { return d.country; }) .entries(csv);
and have found can access values of array if use function when bind data
name.selectall('.name') .data(function(d) { return d.values; <--- accesses nested data }) .text(function(d) { return d.name; <--- nested value })
however having trouble using elsewhere in project. nested value need string called ['starting point']. how can can access value use in d3.filter() example?
var filter = nested_data.filter(function(d) { return ("island" == d['starting point']) });
i'd try: d.values['starting point']
or creating new variable
var nested_values = nested_data(function(d) { return d.values});
but none of valid. should here?
you can filter data on nested data this:
nested_data.map(function(m) { //for each group filter on each value m.values = m.values.filter(function(d) { //return true having starting point island. return d['starting point'] == 'island'; }) })
working code here
Comments
Post a Comment