我想使用 json 变量传递数据。 在下面的示例中,json 是从外部 JSON 文件获取的。 任何人都可以帮助我如何从局部变量传递数据,因为我是 dc.js 的新手
queue()
.defer(d3.json, "sampledata.json") // sampledata.json is an external json file
.await(makeGraphs);
function makeGraphs() {
//function which proceses the data
}
我试过了
var sampledata = [ ....];
queue().defer(d3.json, "sampledata.json") // sampledata.json is an external json file
.await(makeGraphs);
function makeGraphs() {
//function which proceses the data
}
但没有成功。
最佳答案
如果您有一个局部变量,那么使用异步调用来传递它是没有意义的。只需立即将其作为参数传递即可:
var sampleData = [...];//this is your data
makeGraphs(sampleData);//call your function using it as an argument
然后:
function makeGraphs(data){//this is the parameter
//use 'data' here
}
关于javascript - queue.js 从本地变量而不是外部文件传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40235162/