Skip to content

Commit

Permalink
Docs: describe catching events with plugin (#9296)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jun 20, 2021
1 parent c6976e8 commit ed73dce
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/configuration/interactions.md
Expand Up @@ -56,6 +56,30 @@ var chart = new Chart(ctx, {
});
```

Events that do not fire over chartArea, like `mouseout`, can be captured using a simple plugin:

```javascript
var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
// these are the default events:
// events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'],
},
plugins: [{
id: 'myEventCatcher',
beforeEvent(chart, args, pluginOptions) {
const event = args.event;
if (event.type === 'mouseout') {
// process the event
}
}
}]
});
```

For more information about plugins, see [Plugins](../developers/plugins.md)

### Converting Events to Data Values

A common occurrence is taking an event, such as a click, and finding the data coordinates on the chart where the event occurred. Chart.js provides helpers that make this a straightforward process.
Expand Down

0 comments on commit ed73dce

Please sign in to comment.