How to center text in a rect element in d3?
It seems that your code properly computes the center of the rect and places the text at that point, except that the text is left aligned. If so, you just need to change the text-anchor property to center the text. That would be: textElements.style(“text-anchor”, “middle”)