From: Evert Timberg Date: Sun, 17 Apr 2016 16:25:58 +0000 (-0400) Subject: Documentation for creating plugins X-Git-Tag: 2.1.0~68^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f8681a1e4f754235ecd45e4ccb0d3a5533e78a0;p=thirdparty%2FChart.js.git Documentation for creating plugins --- diff --git a/docs/07-Advanced.md b/docs/07-Advanced.md index e272de089..034fee581 100644 --- a/docs/07-Advanced.md +++ b/docs/07-Advanced.md @@ -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 gulp to build the library into a single JavaScript file.