score:0

svg text elements do not have the concept of 'background', you can only style the actual text itself. If you'd like have a background you will need to add that separately with, for instance, an svg rect element:

stackmap.append("rect")
    .attr({
      "class": "background",
      x: 40,
      y: 50,
      width: 100,
      height: 100
    })
    .style("fill", "red");
stackmap.append("text")
    ..etc

Related Query

More Query from same tag