简体   繁体   English

我们如何在 d3js 中向 svg 圆圈添加文本

[英]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?我正在尝试将文本放在由 d3js 创建的圆圈内,我该怎么做?

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/您需要根据 alignment 和锚定/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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