score:1

Accepted answer

lets answer your questions one by one.

  1. to adjust the labels create a more creative function in the transform for the text like so.
  .attr("transform", function(d) { 
    let labelcoords = labelarc.centroid(d); // retrieve the label coords
    let offset = 6; // distance by which you want the labels to move out
    //now get the new label coords by running a function on them
    labelcoords[0] = adjustlabelcoords(labelcoords[0]);
    labelcoords[1] = adjustlabelcoords(labelcoords[1]);
    //this function checks if the coords are negative or positive and applies the offset
    function adjustlabelcoords(coord) {
      if (coord < 0) {
        coord = coord - offset; //if coord is negative, apply a negative offset to move more left or up
      } else if (coord > 0) {
        coord = coord + offset; //if coord is positive, apply a positive offset to move right or down
      }
      return coord;
    }
    return "translate(" + labelcoords + ")"; }
  )
  1. the class .piechartouterlabel is being applied see the screenshot below. so i am not able to understand your issue.

the css style is being applied

you can see that the class is being applied correctly to the text.

  1. your text is already aligned in the center using the text-anchor="middle" attribute. i suppose you want it to be vertically also centered. to do that you can do the following:

change your svgtextlabel to:

        svgtxtlabel
          .attr("text-anchor", "middle")
          .attr("font-size", (labelsize)+'em')
          .attr("transform", `translate(0,-10)`)
          //.attr("dy", '-1.5em')
          .attr("class","piechartcentertextlabel")
          .transition().delay(2000)
          .text("total");

and your svgtxtvalue to:

 let svgtxtvalue =   svg.append("text");
      svgtxtvalue
        .attr("text-anchor", "middle")
        .attr("font-size", (valuesize)+'em')
        .attr("transform", "translate(0,10)")
        .attr("class","piechartcentertextlabel")
        .transition().delay(2000)
        .text(total);

all of this produces:

final result

here is the final stackblitz.


Related Query

More Query from same tag