Fit Text into SVG Element (Using D3/JS)

前端 未结 5 1342
-上瘾入骨i
-上瘾入骨i 2020-12-06 01:53

I want to write text inside a rectangle I create as follows:

body = d3.select(\'body\')

svg = body.append(\'svg\').attr(\'height\', 600).attr(\'width\', 200         


        
5条回答
  •  孤城傲影
    2020-12-06 02:28

    The answer to this question might be relevant. SVG provides no way of wrapping text automatically, but you can embed HTML within SVGs and then use a div for example.

    I've updated the jsfiddle here, but it doesn't work that well together with the animation. If you want to make it work properly and behave like any other SVG element, you'll have to pre-compute the line breaks and insert them manually.

提交回复
热议问题