I want to break long sentence into two line in my SVG text that is generated by D3. But I can't do it in D3/javascript
. I tried with \n
and <br/>
, but they are not working.
<!DOCTYPE html>
<html>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript">
var margin = {top: 80,left: 70, bottom: 80,right: 100},
height = 660 - margin.top - margin.bottom,
width = 1320 - margin.left - margin.right;
var chart = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate("+margin.left+","+margin.top+")");
chart.append('text')
.attr('x', 100)
.attr('y', 100)
.text("I want to have this \n sentence in two lines")
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("font-family", "Helvetica, Arial, sans-serif")
.style("font-weight", "bold")
.style("font-size", "16px" )
.style("fill", "#1ABC9C");
</script>
</body>
</html>