javascript - Accessing d3.js element attributes from the datum? -


i'm trying access cx & cy attributes of specific svg circles have drawn screen using d3.js's .data() function, can out? code that's trying access below.

d3.selectall(".mynode").each( function(d, i){   if(d.someid == targetid){     console.log( d.attr("cx") );    // trying demo point, doesn't work   } } 

i'm quite new d3.js & javascript, i'm not sure if i'm approaching front anyways or perhaps may have missed inbuilt solution?

your code trying svg attribute item of data, when want attribute svg dom element, in:

console.log(d3.selectall(".mynode").attr("cx")); 

this give attribute first non-null element of selection; can filter selection dom element looking for:

console.log(d3.selectall(".mynode").filter(_conditions_).attr("cx")); 

or, if you'd access attributes of selected elements, use this in each function:

d3.selectall(".mynode").each( function(d, i){   if(d.someid == targetid){     console.log( d3.select(this).attr("cx") );   } } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -