score:3

Accepted answer

You have slightly misunderstood what the second argument to d3.data is meant for.

That argument is used for object constancy by providing an id for the data and not as an accessor function, as in most other functions in the d3 API.

However, when a function is passed as the first argument, as is here:

.data(function(d) {
  return d;
})

then it does behave as an accessor function.

In your case, what you want is something along these lines:

var newData = [{"user":"jim","scores":[40,20,30,24,18,40]},
            {"user":"ray","scores":[24,20,30,41,12,34]}];

var myTable = d3.select("body").append("table")
  .selectAll("tr")
  .data(regularData, function(d) {
    return d.user;
  })
  .enter()
  .append("tr")
  .selectAll("td")
  .data(function(d) {
    return d.scores;
  })
  .enter()
  .append("td") 
  .text(function(d) {
    return d;
  });

I have used the user field as the id of the data and have returned the scores in the second call to data to create the td elements.


Related Query

More Query from same tag