Skip to content

Commit

Permalink
Merge pull request #4 from maxpaj/master
Browse files Browse the repository at this point in the history
Added support for ChartJS draw plugins
  • Loading branch information
sedouard authored Dec 9, 2016
2 parents 5e157d7 + aaa30cc commit 2b6c5db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,28 @@ method to release the native resources or you may leak memory:
```
chartNode.destroy();
```
## Adding draw plugins
To use draw plugins, simply use the ``options`` object to add your plugins, like so:
```
var myChartOptions = {
plugins: {
afterDraw: function (chart, easing) {
var self = chart.config; /* Configuration object containing type, data, options */
var ctx = chart.chart.ctx; /* Canvas context used to draw with */
...
}
}
}

var chartJsOptions = {
type: 'pie',
data: myChartData,
options: myChartOptions
}
```
[Read here](http://www.chartjs.org/docs/#advanced-usage-creating-plugins) to see what plugins you can write. In the context of drawing static images, ``beforeDraw`` and/or ``afterDraw`` methods makes most sense to implement.
[Read here](https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D) to see which methods are available for the ``ctx`` object.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class ChartjsNode {
global.document = window.document;
global.window = window;
const Chartjs = require('chart.js');
if(configuration.options.plugins) {
Chartjs.pluginService.register(configuration.options.plugins);
}
this._window = window;
debug('got window');
this._disableDynamicChartjsSettings(configuration);
Expand Down

0 comments on commit 2b6c5db

Please sign in to comment.