[英]Undefined is not a function error d3js
I'm trying to load my own data into this d3.js visualization but I keep getting the error Undefined is not a function
. 我正在尝试将自己的数据加载到d3.js可视化文件中,但我不断收到错误Undefined is not a function
。 The only difference is that, instead of defining freqData
as they did, I defined mine to load from a data file 唯一的区别是,我没有定义freqData
,而是定义了我要从数据文件中加载的代码
var freqData = d3.json("//sjs72/Users/ksdf/file.json", function(fdata) {
console.log(fdata[0]);
});
It happens at the line 它发生在线
fData.forEach(function(d){d.total=d.freq.low+d.freq.mid+d.freq.high;});
Could anyone help me understand where I'm going wrong? 谁能帮助我了解我要去哪里错了?
EDIT: The call I make is dashboard('#dashboard',freqData); 编辑:我打的电话是dashboard('#dashboard',freqData); The function dashboard takes the argument fData, which in this case I'm loading freqData into 功能仪表板采用参数fData,在这种情况下,我正在将freqData加载到
Update: 更新:
I changed my variable definition and the resulting code looks like 我更改了变量定义,结果代码如下
var freqData;
function doSomethingWithData() {
console.log(freqData);
}
d3.json("//sjs72/Users/ksdf/file.json", function(dataFromServer) {
freqData = dataFromServer;
doSomethingWithData();
}
dashboard('#dashboard',freqData);
But now I'm just getting the error 但是现在我只是得到了错误
Uncaught SyntaxError: Unexpected identifier
On the last line of my script 在我脚本的最后一行
You are missing a closing parenthesis for your d3.json()
call. 您缺少d3.json()
调用的d3.json()
括号。 That may very well be producing the issue for you. 那很可能会为您带来问题。 Corrected code: 更正的代码:
var freqData;
function doSomethingWithData() {
console.log(freqData);
}
d3.json("//sjs72/Users/ksdf/file.json", function(dataFromServer) {
freqData = dataFromServer;
doSomethingWithData();
}
); // Added this here
dashboard('#dashboard',freqData);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.