title: replacing d3.js diagram instead of creating a new one every time
body: <p>I`m using d3.js combined with GWT and every time the javascript code for creating a pie chart is called it appends a new one rather than replacing the old one with new values.</p>
  
  <p>How can I change this code so that the old one is removed before appending the new one?</p>
  
  <pre><code>var svg = d3.select(".body").append("svg")
              .attr("width", width)
              .attr("height", height)
            .append("g")
              .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
  </code></pre>