[3.4.1] not able to detect which bar was clicked (working in 2.x) #9387
-
Expected BehaviorIn 2.x when clicking on the bar of the bar chart I was able to tell which bar was clicked, it doesn't work any more in 3.x and I don't see it mentioned in the migration guide Current BehaviorSecond argument of the options.onClick contains always all bars (series? sorry, not sure about the nomenclature, see the reproduction) Possible SolutionPass only the clicked bar instead of all, or add additional argument to the onClick Steps to Reproducehttps://codepen.io/jkarczm/pen/VwbjyRa?editors=1010 Click the left bar and the right bar - how to distinguish which one was clicked? ContextI have daily chart with bar per user, so clicking on the bar shows the data for clicked date and user Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
One option is to set the interaction mode to Another option is to have the |
Beta Was this translation helpful? Give feedback.
-
Excelent, thank you! Am I right about this change not being mentioned in the migration guide though? |
Beta Was this translation helpful? Give feedback.
-
BTW, both examples link to the same codepen |
Beta Was this translation helpful? Give feedback.
-
Sorry about that; I fixed the links. I looked back at the 2.9 source code and it appears that it called |
Beta Was this translation helpful? Give feedback.
-
I think I found the discrepancy. In 2.9, the hover mode defaulted to |
Beta Was this translation helpful? Give feedback.
One option is to set the interaction mode to
'nearest'
https://codepen.io/etimberg/pen/mdmEXbm?editors=1010Another option is to have the
onClick
handler look directly under the mouse point usinggetElementsAtEventForMode
https://codepen.io/etimberg/pen/xxdOpox?editors=1010