Need help on d3 project

When I hover over the graph, it returns undefined values. I couldn’t figure it out

            years[i] +
              '<br>' +
              '$' +
              GDPs[i] +
              ' Billion'
.on('mouseover', function (d, i) {

Here you’re using i like it is an index but this is not actually what it is.

I suggest you console.log both d and i to check it out.

In the example project, it is used exactly like that and working.

or I didn’t get it :confused:

In your project you use the latest version of d3.js and the example project uses version 4.2.2. One of the differences is the way events are handled.

That’s why I really suggest console.logging the values that you’re using instead of looking at the solution.

.on('mouseover', function (d, i) {
    console.log(d, i);

years[i] is undefined because you expect function arguments to be data and index but are they really what you think they are?

1 Like