简体   繁体   中英

how can we add text to a svg circle in d3js

I'm trying to put text inside circle which is created by d3js, how can I do that?

const svg = d3.select("#circle").append("svg").attr("width", 300).attr("height", 300)
const text = ['Team']
svg.append('circle')
  .attr('cx', 100)
  .attr('cy', 75)
  .attr('r', 35)
  .attr('stroke', '#41778D')
  .attr('stroke-width', 5)
  .attr('fill', '#ffffff');

svg.append('circle')
  .attr('cx', 100)
  .attr('cy', 75)
  .attr('r', 27)
  .attr('stroke', '#41778D')
  .attr('fill', '#ffffff');

Similar to appending your circles:

svg.append('text')
  .text(text[0])
  .attr('y', 100)
  .attr('x', 75)

You'll need to adjust based on the alignment and anchoring/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM