【问题标题】:how can we add text to a svg circle in d3js我们如何在 d3js 中将文本添加到 svg 圆圈
【发布时间】:2022-01-01 04:15:04
【问题描述】:

我正在尝试将文本放在由 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');

【问题讨论】:

    标签: javascript d3.js


    【解决方案1】:

    类似于添加你的圈子:

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

    您需要根据对齐和锚定进行调整/

    【讨论】:

    • 成功了,谢谢
    猜你喜欢
    • 2020-10-19
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-02
    相关资源
    最近更新 更多