D3 test #1 data return undefined

Hi, the problem is in the tooltip part, the function has no acces to the data, why is that? how can i fix it?

Let the code-pen here : https://codepen.io/StayCoold/pen/abPjjQv

thanks for your time !!

the error is because of the onmouseover listener where the first parameter is related to event itself the second arg is where you’ll have actual data for the graph bar .

.on('mouseover', function(_,d){

     tooltip
     .html(`${d[1]}`)
     .attr('data-date',  d3.timeFormat("%Y-%m-%d")(d[0]) )
    })

second thing is to set the id atttribute to tooltip but you’ve set the class attribute (in CSS too)

const tooltip = d3.select('body')
    .append("div")
    .attr("class", 'tooltip')  // should be "id"
1 Like