問題出在這里 -d[0]和d[1]return undefined,但我不知道如何訪問資料。
我試過d.Wavelength(列名在d[0]),但這不起作用。在示例(下面的鏈接)d.value中使用了,但我需要訪問d[0]和 處的值d[1]。
function m_over(data){
ttip.datum(data)
.style("visibility","visible")
.text(function(d){
return ("Wavelength: " d[0] ", Sample_1_Absorbance: " d[1])
})
}
function m_out(data){
ttip.style("visibility","hidden");
}
function m_move(data){
ttip.style("top", (event.pageY - 10) "px").style("left", (event.pageX 10) "px");
}
svg.selectAll('circle_samp_1')
.data(data_in_range)
.enter()
.append('circle')
.attr('cx', (d) => xScale(d[0]))
.attr('cy', (d) => yScale(d[1]))
.attr('r', 7)
.attr('fill', 'rgba(0,0,0,0.1)')
.attr('stroke', 'rgba(0,0,0,0.9)')
.attr('stroke-width', 1)
.attr('class', 'points')
.style('pointer-events', 'all')
.on("mouseover",function (d){
return m_over(d)
})
.on("mousemove", function (d) {
return m_move(d)
})
.on("mouseout", function (d) {
return m_out(d)
});
我正在嘗試重新創建
如果您想查看我的資料或代碼的其余部分,請告訴我,我會將其添加進來。在此先感謝您。
uj5u.com熱心網友回復:
我認為您需要調整您的事件偵聽器。
例如,在“mouseover”函式中,第一個引數是滑鼠事件,第二個引數是附加到分派該事件的元素的資料......
.on("mouseover",(event, d)=>{
//check what we're passing to the m_over function
console.log('data:', d);
m_over(d);
})
這是一個非常簡單的例子,說明了這個概念 https://codepen.io/tomp/pen/wveRNmV
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/326022.html
標籤:javascript d3.js
