d3.js简单区域图示例...获取“未定义”错误;我想我需要一个return语句? [英] d3.js simple area chart example ... getting "undefined" error; I think I need a return statement?
问题描述
我正在通过d3.js.org上的示例学习d3.js
I'm studying d3.js by working through the examples on d3.js.org
我尝试在自己的键入,所以我将理解变量和函数。
I tried typing it in myself so I'll understand the variables and functions.
脚本调用data.tsv生成图表。
The script calls on data.tsv to make the chart.
我有一个'undefined'不是一个对象的错误。
Well, when loading data.tsv, I got an "'undefined' is not an object" error.
所以我提出了一些,然后就进行了&将bl.ock的原始代码复制并粘贴到我的编辑器中,将其d3.v3.js更改为d3.v2.js
So I fiddled some, then just went ahead & copied and pasted bl.ock's original code into my editor, changing his d3.v3.js into d3.v2.js
同样的错误。
我觉得我的data.tsv在我的机器上的正确目录,与d3.v2.js相同的目录。
I feel that I have data.tsv in the correct directory on my machine, same directory as d3.v2.js.
抛出错误第二行:
d3.tsv("data.tsv", function(error, data) {
data.forEach(function(d) {
d.date = parseDate(d.date);
d.close = +d.close;
});
这里是一个错误的图片:
https://twitter.com/maggie_a_lee/status/273858397173080064/photo/1
here's a pic of the error: https://twitter.com/maggie_a_lee/status/273858397173080064/photo/1
感谢所有!!
推荐答案
这与D3库的版本相关;目前正在从v2转换到v3: a href =https://github.com/mbostock/d3/wiki/Release-Notes =noreferrer> https://github.com/mbostock/d3/wiki/Release-Notes
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
您正在使用的示例已针对v3进行了修改,但您仍在加载v2库。
The example you are working from has already been modified for v3, but you are still loading the v2 library.
对于d3.tsv,两个版本之间的差异与回调签名相关:
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.
这篇关于d3.js简单区域图示例...获取“未定义”错误;我想我需要一个return语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!