相关疑难解决方法(0)

在圈内包裹文字

我正在使用d3绘制UML图,并希望将文本包装在用d3绘制的形状中.我已经得到了下面的代码,并找不到解决方案,使文本"适合"我的形状(见下图).

var svg =  d3.select('#svg')
    .append('svg')
        .attr('width', 500)
        .attr('height', 200);

var global = svg.append('g');

global.append('circle')
      .attr('cx', 150)
      .attr('cy', 100)
      .attr('r', 50);

global.append('text')
  .attr('x', 150)
  .attr('y', 100)
  .attr('height', 'auto')
  .attr('text-anchor', 'middle')
  .text('Text meant to fit within circle')
  .attr('fill', 'red');
Run Code Online (Sandbox Code Playgroud)

结果

javascript geometry svg text d3.js

12
推荐指数
3
解决办法
8937
查看次数

标签 统计

d3.js ×1

geometry ×1

javascript ×1

svg ×1

text ×1