Accepted answer

Suggested reading:

And also:

FYI, You just have to check the parameters passed to x remember that doing .attr('width', x) will call x with the datum itself AND the index, if x doesn't do anything with the index then you're good to go :)


x is a function that expect an argument an return an scaled result. D3 sends the data item as argument and this is the magic.


In this example x is a function which is simply passed by reference. By using .attr("width", function(d){return x(d);}) you are just wrapping x into another function, which doesn't add anything to your program.

Related Query