]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Docs: describe catching events with plugin (#9296)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 20 Jun 2021 17:11:30 +0000 (20:11 +0300)
committerGitHub <noreply@github.com>
Sun, 20 Jun 2021 17:11:30 +0000 (13:11 -0400)
docs/configuration/interactions.md

index 8ec5babb6868ee30a0d776eb3ce75e13d8a6ab58..370244bae415456fd5e14ebc88e95cddba4d4967 100644 (file)
@@ -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.