d3.js simple area chart example … getting “undefined” error; I think I need a return statement?

前端 未结 1 447
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 05:57

I\'m studying d3.js by working through the examples on d3.js.org

I\'m starting with \"area chart\" at http://bl.ocks.org/3883195

I tried typing it in myself so I

相关标签:
1条回答
  • 2021-01-24 06:48

    This related to the version of the D3 library; currently it is transitioning from v2 to v3: https://github.com/mbostock/d3/wiki/Release-Notes

    The example you are working from has already been modified for v3, but you are still loading the v2 library.

    For d3.tsv the difference between the two version is related to the callback signature:

    v2:

    d3.tsv("data.tsv", function(data) { 
      data.forEach(function(d) { 
         d.date = parseDate(d.date);
         d.close = +d.close;
      });
    

    v3:

    d3.tsv("data.tsv", function(error, data) { 
      data.forEach(function(d) { 
         d.date = parseDate(d.date);
         d.close = +d.close;
      });
    

    That means that in your case the actual data got stored in the error argument.

    0 讨论(0)
提交回复
热议问题