我正在使用库“ TimeLinesChart”,并希望将EventListener添加到可视化中的所有矩形。问题是,应该在document.getElementsByClassName('series-segment');
中的元素在那里,但是长度为0。因此无法使用for循环访问它们。
function showSequences(d){
TimelinesChart()(document.getElementById('action-visualizer'))
.xTickFormat(n => +n)
.leftMargin(20)
.rightMargin(60)
.width(1700)
.maxLineHeight(50)
.timeFormat('%Q')
.zQualitative(true)
.data(d);
var boxes = document.getElementsByClassName('series-segment');
// -> Array of elements (length not 0 in the console)
console.log(boxes.length);
// -> 0
我知道问题出在现场直播,我要的时候长度是0。其他线程通过使用超时或类似方法来解决此问题。但是,在等待此类加载所有内容时,所有方法都无效。我该怎么办?
答案很简单!我在库的文档中找到了一个onSegmentClick([function])
,它可以激活一个侦听器,以便在这些段上进行简单单击。谢谢您的帮助...