title: TypeError: d is undefined in nvd3.js
body: <p>I've got a working <code>lineWithFocusChart</code> and I needed to copy it into another page.
  Now, when I run it I see in Firebug's console this message:</p>
  <blockquote>
  <p>TypeError: d is undefined <em>scatter.js (line 240)</em></p>
  <p>if (d.data.length === 0)</p>
  </blockquote>
  <p>After some trial and error with Firebug's debugging feature I haven't found a solution yet, so hI'm giving you my code to see if there's something I'm missing.</p>
  <p>HTML Page:</p>
  <pre><code>&lt;div id=&quot;grafico2&quot; class=&quot;graficoContent&quot; style=&quot;border: 1px solid blue; opacity:0&quot;&gt;
      &lt;link href=&quot;charts/line/line.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
      &lt;script src=&quot;charts/line/libs/nv.d3.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/libs/tooltip.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/libs/utils.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/libs/models/legend.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/libs/models/axis.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/libs/models/scatter.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/libs/models/line.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/libs/models/lineWithFocusChart.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;charts/line/line.js&quot;&gt;&lt;/script&gt;
      &lt;div id=&quot;line&quot; class='with-3d-shadow with-transitions'&gt;
          &lt;svg style=&quot;height: 700px;&quot;&gt;&lt;/svg&gt;
      &lt;/div&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
          var lineChart = new Line();
      lineChart.draw();
      &lt;/script&gt;
  &lt;/div&gt;
  </code></pre>
  <p>line.js:</p>
  <pre><code>function Line() {
      var chart               = {};
  
      var lineChart           = nv.models.lineWithFocusChart()
                                              .x(function(d){
                                                  return new Date(d.x);
                                              });
  
      var dateParser          = d3.time.format(&quot;%Y-%m-%d&quot;).parse;
  
      function getArtworkFromKey(key){
          return testData().filter(function(el){ return el.key == key; })[0].artwork;
      }                   
  
      chart.draw = function(){        
          var data = testData();      
          nv.addGraph(function(){
              lineChart.margin({bottom: 40, left:50});
              var maxStreams = d3.extent(data, function(d,i){ 
                                              return d.values[i].y;
                                          })[1];
              lineChart.yDomain([0, maxStreams*(6/5)]);
              lineChart.lines.xScale(d3.time.scale());
              lineChart.xAxis.tickFormat(function(d) {
                              return d3.time.format(&quot;%d-%m-%Y&quot;)(new Date(d)); 
                         })
                         .tickValues(function(d,i){
                              var tmp = d[i].values.map(function(el){ return el.x;});
                              var res = [];                   
                              res.concat.apply(res, tmp);                 
                              return res;
                         });
              lineChart.lines2.xScale(d3.time.scale());
              lineChart.x2Axis.tickFormat(function(d) { 
                              return d3.time.format(&quot;%d-%m-%Y&quot;)(new Date(d)); 
                          })
                          .tickValues(function(d,i){
                              var tmp = d[i].values.map(function(el){ return el.x;});
                              var res = [];
                              res.concat.apply(res, tmp);
                              return res; 
                          });
              lineChart.yAxis.tickFormat(d3.format(&quot;.2s&quot;));
              lineChart.y2Axis.tickFormat(d3.format(&quot;.2s&quot;));
              lineChart.tooltipContent(function(key, y, e, graph) {
                  var x = d3.time.format(&quot;%d-%m-%Y&quot;)(new Date(graph.point.x));
                  var y = String(graph.point.y);
                  var y = String(graph.point.y)  + ' streams';                
                  tooltip_str = '&lt;center&gt;&lt;image src=&quot;' + getArtworkFromKey(key) + '&quot;/&gt;&lt;br/&gt;&lt;b&gt;'+key+'&lt;/b&gt;&lt;/br&gt;' + y + ' il ' + x + '&lt;/center&gt;';
                  return tooltip_str;
              });         
              d3.select('#line svg')
                .datum(data)
                .call(lineChart);          
              d3.selectAll('.nv-x.nv-axis &gt; g').attr('transform', 'translate(0,10)');                     
              return lineChart;
          });
      };
  
      return chart;
  }
  </code></pre>
  <p>I'm using a <code>testData()</code> function which returns this <em>JSON</em> object</p>
  <pre><code>function testData() {
          return [
                  {
                      key: &quot;Clean Bandit - Rather Be&quot;,
                      values: [
                          {
                              x: &quot;2014-04-27&quot;,
                              y: 2504054
                          },
                          {
                              x: &quot;2014-04-20&quot;,
                              y: 1905117
                          },
                          {
                              x: &quot;2014-04-13&quot;,
                              y: 1513407
                          },
                          {
                              x: &quot;2014-04-06&quot;,
                              y: 893984
                          }
                      ],
                      artwork: &quot;http://o.scdn.co/300/f6c9e55802a1dbf3c4a346dd58097ad0cafe9a94&quot;
                  },
                  {
                      key: &quot;Calvin Harris - Summer&quot;,
                      values: [
                          {
                              x: &quot;2014-04-27&quot;,
                              y: 1504054
                          },
                          {
                              x: &quot;2014-04-20&quot;,
                              y: 805117
                          },
                          {
                              x: &quot;2014-04-13&quot;,
                              y: 713407
                          },
                          {
                              x: &quot;2014-04-06&quot;,
                              y: 593984
                          }
                      ],
                      artwork: &quot;http://o.scdn.co/300/f6c9e55802a1dbf3c4a346dd58097ad0cafe9a94&quot;
                  },
                  {
                      key: &quot;David Guetta - Bad&quot;,
                      values: [
                          {
                              x: &quot;2014-04-27&quot;,
                              y: 1504054
                          },
                          {
                              x: &quot;2014-04-20&quot;,
                              y: 505117
                          },
                          {
                              x: &quot;2014-04-13&quot;,
                              y: 213407
                          },
                          {
                              x: &quot;2014-04-06&quot;,
                              y: 93984
                          }
                      ],
                      artwork: &quot;http://o.scdn.co/300/f6c9e55802a1dbf3c4a346dd58097ad0cafe9a94&quot;
                  },
                  {
                      key: &quot;Iggy Azalea - Fancy&quot;,
                      values: [
                          {
                              x: &quot;2014-04-27&quot;,
                              y: 2504054
                          },
                          {
                              x: &quot;2014-04-20&quot;,
                              y: 1405117
                          },
                          {
                              x: &quot;2014-04-13&quot;,
                              y: 513407
                          },
                          {
                              x: &quot;2014-04-06&quot;,
                              y: 293984
                          }
                      ],
                      artwork: &quot;http://o.scdn.co/300/d71d05ded1704bcf849465dd5e76e196847d1c0a&quot;
                  }
          ];
      }
  </code></pre>
  <p>Do you know why is it failing?</p>