title: D3 X-Axis long label overlapping
body: <p>I have a D3 Bar chart which X-Axis label is overlapping onto each other. I have the following:</p>
  
  <p>// word wrapping for x axis</p>
  
  <pre><code>svg.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis)
  </code></pre>
  
  <p>attempted to follow <a href="http://bl.ocks.org/mbostock/7555321" rel="noreferrer">http://bl.ocks.org/mbostock/7555321</a> by adding the necessary function but to no valid. Anyone able to advise?</p>
  
  <pre><code>function wrap(text, width) {
    text.each(function() {
      var text = d3.select(this),
          words = text.text().split(/\s+/).reverse(),
          word,
          line = [],
          lineNumber = 0,
          lineHeight = 1.1, // ems
          y = text.attr("y"),
          dy = parseFloat(text.attr("dy")),
          tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em");
      while (word = words.pop()) {
        line.push(word);
        tspan.text(line.join(" "));
        if (tspan.node().getComputedTextLength() &gt; width) {
          line.pop();
          tspan.text(line.join(" "));
          line = [word];
          tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
        }
      }
    });
  </code></pre>
  
  <p>thank you.</p>