d3.js - Create Unique Path Within Each SVG Group Element Using D3 -
i'm trying create 50 svg groups each group containing path draws particular state. however, can't figure out how access state data svg group when creating state path group. can put me on right track? thanks!
var coords = [ { 'id':'hi', 'class':'state hi', 'd': 'm 233.08751,519.30948 1.93993, ...' }, { 'id':'ak', 'class':'state ak', 'd': 'm 158.07671,453.67502 -0.32332, ...'} ... ]; // select svg var svgcontainer = d3.select('svg'); // create groups state data var groups = svgcontainer.selectall('g') .data(coords) .enter() .append('g'); // create state path each group groups.each(function(g){ g.select('path') .data(___need return path data here___) .enter() .append('path'); }); uncaught typeerror: g.select not function
assuming data valid , want handle new elements (no updates), should work:
// select svg var svgcontainer = d3.select('svg'); // create groups state data var groups = svgcontainer.selectall('g') .data(coords) .enter() .append('g') .append('path') .attr('d', function (d) { return d.d; }); i have created pretty simplified fiddle example.
if still want use .each function, can proceed follows:
groups.each(function (d, i){ // `this` (in context) bound current dom element in enter selection d3.select(this).append('path').attr('d', d.d); }); for further details, can check api documentation.
hope helps.
Comments
Post a Comment