title: NVD3 - How to refresh the data function to product new data on click
body: <p>I have a line chart and every time the page refresh it changes the data, which is great but I need to to refresh by a user click. This is because there will eventually be other input fields on the page and refreshing the page would destroy their current session.</p>
  
  <p>jsfiddle - <a href="http://jsfiddle.net/darcyvoutt/dXtv2/" rel="noreferrer">http://jsfiddle.net/darcyvoutt/dXtv2/</a></p>
  
  <p>Here is the code setup to create the line:</p>
  
  <pre><code>function economyData() {  
  
      // Rounds
      var numRounds = 10;
  
      // Stability of economy
      var stable = 0.2;
      var unstable = 0.6;
      var stability = unstable;
  
      // Type of economy
      var boom = 0.02;
      var flat = 0;
      var poor = -0.02;
      var economyTrend = boom;
  
      // Range    
      var start = 1;
      var max = start + stability;
      var min = start - stability;
  
      // Arrays
      var baseLine = [];
      var economy = [];
  
      // Loop
      for (var i = 0; i &lt; numRounds + 1; i++) {    
  
        baseLine.push({x: i, y: 1});
  
        if (i == 0) {
  
          economyValue = 1;
  
        } else {
  
          var curve = Math.min(Math.max( start + ((Math.random() - 0.5) * stability), min), max);        
  
          economyValue = Math.round( ((1 + (economyTrend * i)) * curve) * 100) / 100;
  
        }
  
        economy.push({x: i, y: economyValue});
  
      }
  
      return [
        {
          key: 'Base Line',
          values: baseLine   
        },
        {
          key: 'Economy',
          values: economy  
        }
      ];
    }
  </code></pre>
  
  <p>Here is what I tried to write but failed for updating:</p>
  
  <pre><code>function update() {
        sel = svg.selectAll(".nv-line")
        .datum(data);
  
        sel
          .exit()
          .remove();
  
        sel
          .enter()
          .append('path')
            .attr('class','.nv-line');
  
        sel
          .transition().duration(1000);
  
    };
  
    d3.select("#update").on("click", data);  
  </code></pre>