]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Documentation for creating plugins
authorEvert Timberg <evert.timberg+github@gmail.com>
Sun, 17 Apr 2016 16:25:58 +0000 (12:25 -0400)
committerEvert Timberg <evert.timberg+github@gmail.com>
Sun, 17 Apr 2016 16:25:58 +0000 (12:25 -0400)
docs/07-Advanced.md

index e272de0891e60a15b14eb96fc87263342a2897f7..034fee5816a30b8c16a3c8675db5b1a81a50266f 100644 (file)
@@ -366,6 +366,32 @@ The built in controller types are:
 #### Bar Controller
 The bar controller has a special property that you should be aware of. To correctly calculate the width of a bar, the controller must determine the number of datasets that map to bars. To do this, the bar controller attaches a property `bar` to the dataset during initialization. If you are creating a replacement or updated bar controller, you should do the same. This will ensure that charts with regular bars and your new derived bars will work seamlessly.
 
+### Creating Plugins
+
+Starting with v2.0.3, you can create plugins for chart.js. To register your plugin, simply call `Chart.pluginService.register` and pass your plugin in.
+Plugins will be called at the following times
+* Start of initialization
+* End of initialization
+* Start of update
+* End of update
+* Start of draw
+* End of draw
+
+Plugins should derive from Chart.PluginBase and implement the following interface
+```javascript
+{
+       beforeInit: function(chartInstance) { },
+       afterInit: function(chartInstance) { },
+
+       beforeUpdate: function(chartInstance) { },
+       afterUpdate: function(chartInstance) { },
+
+       // Easing is for animation
+       beforeDraw: function(chartInstance, easing) { },
+       afterDraw: function(chartInstance, easing) { }
+}
+```
+
 ### Building Chart.js
 
 Chart.js uses <a href="http://gulpjs.com/" target="_blank">gulp</a> to build the library into a single JavaScript file.