score:1

Accepted answer

The problem here is that you're using hierarchical data and there is one case where d.parent isn't defined: the root node of your hierarchy. It's simple enough to fix, though: just check whether or not the parent node is present:

cells
  .append('title')
  .text(function (d) {
    if ( d.parent ) {
      return categoryKey + " : " + d.parent.name + "\n" + groupKey + " : " + d.name + "\n" + sizeKey + " : " + toCommas(d.value)
    }
    return d.name; // or whatever you want to do for the root node case
  });

You can compress this into a single line with a ternary if-else:

cells
  .append('title')
  .text(function (d) {
      return ( d.parent ? categoryKey + " : " + d.parent.name + "\n" : 'root node' )
      + groupKey + " : " + d.name + "\n" + sizeKey + " : " + toCommas(d.value)
    }

(code untested)


Related Query

More Query from same tag