mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Docs: describe catching events with plugin (#9296)
This commit is contained in:
parent
c6976e8975
commit
ed73dce18b
@ -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
|
### 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.
|
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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user