2

所以我一直在尝试使用 D3plus 将文本包裹在圆圈内,但没有成功。在我的应用程序中,我有几个圆圈/文本对,组合成一个“g”元素。在我的代码中,在创建“g”元素并向其附加圆圈和文本后,我调用 d3plusd3plus.textwrap()函数,如下所示:

d3plus.textwrap()
  //selecting the first text element
  .container(d3.select("#Text0"))
  .draw();

但是,文本并没有被包装,而是消失了。文本仍然作为 DOM 中的元素可见,但由于某种原因,它的大小变为 0x0。有谁知道这里有什么问题?

4

1 回答 1

3

使用方法resize as true如下代码:

<!DOCTYPE html>
<meta charset="utf-8">
<script src="//d3plus.org/js/d3.js"></script>
<script src="//d3plus.org/js/d3plus.js"></script>
<style>
  svg {font-family:"Helvetica","Arial",sans-serif;height: 425px;margin: 25px; width: 400px;}
  .type {fill: #888;text-anchor: middle;}
  .shape {fill: #eee;stroke: #ccc;}
</style>
<svg>
  <circle class="shape" r="85px" cx="275px" cy="300px"></circle>
  <text id="circleResize" class="wrap" y="260px" x="200px" font-size="12">
Appeared Text inside circle </text> 
</svg>
<script>  
  d3plus.textwrap()
.container(d3.select("#circleResize"))
.resize(true)
.draw();
</script>
于 2016-08-31T05:49:24.133 回答