【发布时间】:2022-01-11 19:34:32
【问题描述】:
我正在使用面向对象的图表并根据滚动位置设置数据。 我正在使用 d3.csv() 通过 then() 加载数据,如下所示:
const chart = new Chart(instatiatechartfunctions);
let dataObj1 = d3.csv('datapath', dataparsefunction);
let dataObj2 = d3.csv('datapath2', dataparsefunction);
let dataArr = [dataObj1,dataObj2];
function init(data){
chart.setData(data);
}
let g3 = scrollerfunction().settings()
.on('active', function(i){
dataArr[i].then(init); //error here
});
将滚动条库与图表的所有代码一起包含在内对我来说是相当复杂的,所以我希望以上内容足够清楚。
我的主要问题是在then() 中调用init 而不使用 () 会显示图表,但会在标题中返回错误。当我使用括号 (then(init())) 时,出现以下错误:
Uncaught TypeError: Cannot read properties of undefined (reading '0')
我正在使用 d3.v6 有人可以帮忙吗?
【问题讨论】:
-
.on('active', function(i){console.log(i, dataArr.length, dataArr[i]); ....所以调试一下看看是怎么回事。
标签: javascript d3.js