Accepted answer

When you created your transformed dataset to pass to the d3.layout.stack() layout, you lost the information of the name of the fruit corresponding to each data point.

If you console.log(dataset) you'll see that it is an array of 4 arrays, one for each fruit, and each array is composed of objects representing the x and y values for the data point. You need to also keep track of the fruit:

var dataset = d3.layout.stack()(["red Delicious", "mcintosh", "oranges", "pears"].map(function(fruit) {
  return {
      return {x: parse(d.year), y: +d[fruit], "fruit":fruit};

That way later in your tooltip text, you can reference d['fruit']

Working fork of your fiddle:

Related Query

More Query from same tag