Skip to content

Commit

Permalink
Add a note on how to use getElementAtEvent in a click handler
Browse files Browse the repository at this point in the history
  • Loading branch information
etimberg committed Jul 4, 2017
1 parent 7d60857 commit 9ec78ce
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/developers/api.md
Expand Up @@ -128,6 +128,19 @@ myLineChart.getElementAtEvent(e);
// => returns the first element at the event point.
```

To get an item that was clicked on, `getElementAtEvent` can be used.

```javascript
function clickHandler(evt) {
var item = myChart.getElementAtEvent(evt)[0];

if (item) {
var label = myChart.data.labels[firstPoint._index];
var value = myChart.data.datasets[firstPoint._datasetIndex].data[firstPoint._index];
}
}
```

## .getElementsAtEvent(e)

Looks for the element under the event point, then returns all elements at the same data index. This is used internally for 'label' mode highlighting.
Expand Down

0 comments on commit 9ec78ce

Please sign in to comment.