Studying d3, and when I create a simple array of numbers, then try to bind the data to a simple set of elements, but use the key function, it runs through the loop twice. The first time this tells me that the values โโof the array are undefined. The second time they are available.
Here is the html:
<div class="testBind"></div> <div class="testBind"></div> <div class="testBind"></div>
And here is js:
var numbers = [1, 2, 3]; function whichNumber(n){ console.log('n----:' + n); return n; } var testKeyFunction = d3.selectAll("div.testBind").data(numbers, whichNumber);
When I run this, I get:
n----:undefined n----:undefined n----:undefined n----:1 n----:2 n----:3
Here is the violinist: http://jsfiddle.net/5f8mo2sa/3/
The reason this is a problem (except wtf) is because when the data is an array of objects, and I try to reference the key in this function, it throws an undefined error.
source share