title: d3 - Change text label when data updates
body: <p>Using d3, I created a bar graph that displays the text value of each bar on it. I am toggling between two different data sets through a click event on a button. The data sets change successfully on mousedown, i.e. the bar graphs change in size as they should, but I am unable to change the text labels on the bars. My redrawText function does not do anything, and calling my drawText function again just redraws the data on top of the previous label (as one would expect). I am looking for a way to remove the old label and redraw the label reflecting the new data inside my removeText function.</p>
  
  <p>Here is my drawText function, which is called initially to create the label. 'datachoose' is the name of the variable that is selected to graph the proper data set.</p>
  
  <pre><code>function drawText(dataChoose) {
       new_svg.selectAll("text.dataChoose")
          .data(dataChoose)
          .enter().append("text")
          .text(function(d) {
                  return d;
                  })
      /* removed some transform code */
       .attr("fill", "white")
       .attr("style", "font-size: 12; font-family: Garamond, sans-serif");
  }
  </code></pre>
  
  <p>Here are the relevant parts of my mousedown event handler, which is used to update the data set and redraw the graph:</p>
  
  <pre><code>.on("mousedown", function() {
  
          if (dataChoose == data) {
              dataChoose = data2;
          }
  
          else {
          dataChoose = data;
          }
  
          redraw(dataChoose);
          redrawText(dataChoose);
      });
  </code></pre>
  
  <p>and here is my redrawText() function</p>
  
  <pre><code>function redrawText(dataChoose) {
  
      var new_text = new_svg.selectAll("text.dataChoose")
          .data(dataChoose);
  
      new_text.transition()
       .duration(1000)
       .text(function(d) {
          return d;
          })
  
  /* removed transform code */
  
      .attr("fill", "white")
      .attr("style", "font-size: 16; font-family: Garamond, sans-serif");
  }
  </code></pre>