What returns .data (function (d) {return d;}) in d3?

var matrix = [
  [11975,  5871, 8916, 2868],
  [ 1951, 10048, 2060, 6171],
  [ 8010, 16145, 8090, 8045],
  [ 1013,   990,  940, 6907]
];

var tr = d3.select("body").append("table").selectAll("tr")
    .data(matrix)
  .enter().append("tr");

var td = tr.selectAll("td")
    .data(function(d) { return d; })
  .enter().append("td")
    .text(function(d) { return d; });

I do not understand what d represents here. Can someone kindly guide me through the code?

Link: https://github.com/mbostock/d3/wiki/Selections#wiki-remove

+3
source share
1 answer

You have a nested selection , i.e. you make a choice, and then choose based on that. This is also an explanation of the function in the argument .data()- it is nested below the first, so it can refer to it.

, .data(matrix). D3 - , .. . tr. , .data(), , (tr s). function(d) { return d; } , D3 . , D3 - , .

+3

All Articles