Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

onClick datasetIndex is always 0 on line chart

Open jwtea opened this issue 7 years ago • 2 comments

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

jwtea avatar Oct 22 '19 15:10 jwtea

You can call chart.getElementsAtEventForMode(event, mode, options) to get different events that current hover mode would return.

kurkle avatar Oct 31 '19 19:10 kurkle

@kurkle Thanks didn't see that

jwtea avatar Nov 26 '19 09:11 jwtea