Skip to content
Advertisement

D3 mouse interactivity issues, circles not appearing at data points

I’m implementing some D3 code in class format so that I have a reusable chart.

The errors are as follows:

GetElementsByClassName returns an HTMLCollection of length 0, but elements to be selected are classed correctly.

Circles appear at x0 and yMax, rather than at data positions (Issue is probably connected to the first).

Text is not appended to circle and not visible (This might work when the circles work).

I’m implementing this pretty much exactly as it looks, with the exception that I’m putting tooltips on 2/4 of the lines, and I’m using a class.

JavaScript

As you can see the mouse interactions are pretty janky so I hope someone can help.

Advertisement

Answer

There are some differences between arrow function and regular function.
Fixed some more errors:

JavaScript

Instead of listing all of them, I’ve created a diff file. Download and check. Left side is the original code.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement