score:3

Accepted answer

You can update your append text code with following code.

text.enter()
 .append("text")
 .attr("dy", ".35em")
 .append('svg:tspan')
 .attr('x', 0)
 .attr('dy', 0)
 .text(function(d) { return d.data.label; })
 .append('svg:tspan')
 .attr('x', 0)
 .attr('dy', 20)
 .text(function(d) { return d.data.value; });

Append two tspan to your text element

Updated Fiddle here

score:2

You need to do it like this:

    var text = svg.select(".labels").selectAll("text")
        .data(pie(data), key);
  //make a group  
    var textg = text.enter().append("g");
  //to the group append text for label
    textg
        .append("text")
        .attr("dy", ".35em")
        .text(function(d) {
            return d.data.label;
        });
  //to the group append text for value  
    textg.append("text")
      .attr("dy", "1.95em")
      .text(function(d) { return d.data.value; });  

Working code here


Related Query

More Query from same tag