Chart.js
Chart.js copied to clipboard
onClick datasetIndex is always 0 on line chart
Expected Behavior
onClick event should return the correct dataset index.
Current Behavior
datsetIndex on line chart is always 0.
Possible Solution
Had a dig through, the line chart defaults to a deprecated hover mode Setting this to nearest seems to be the only way to get the chart click events to behave properly.
Steps to Reproduce (for bugs)
https://codepen.io/jwtea/pen/gOOgJKr?editors=1111
Context
Can't access the correct data for a given click event on a data point when using a line chart.
Environment
- Chart.js version: 2.8.0
- Browser name and version: All browsers
- Link to your project: https://codepen.io/jwtea/pen/gOOgJKr?editors=1111
You can call chart.getElementsAtEventForMode(event, mode, options) to get different events that current hover mode would return.
@kurkle Thanks didn't see that