Skip to content

Commit 2b6c5db

Browse files
authored
Merge pull request #4 from maxpaj/master
Added support for ChartJS draw plugins
2 parents 5e157d7 + aaa30cc commit 2b6c5db

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,28 @@ method to release the native resources or you may leak memory:
6363
```
6464
chartNode.destroy();
6565
```
66+
67+
## Adding draw plugins
68+
69+
To use draw plugins, simply use the ``options`` object to add your plugins, like so:
70+
```
71+
var myChartOptions = {
72+
plugins: {
73+
afterDraw: function (chart, easing) {
74+
var self = chart.config; /* Configuration object containing type, data, options */
75+
var ctx = chart.chart.ctx; /* Canvas context used to draw with */
76+
...
77+
}
78+
}
79+
}
80+
81+
var chartJsOptions = {
82+
type: 'pie',
83+
data: myChartData,
84+
options: myChartOptions
85+
}
86+
```
87+
88+
[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.
89+
90+
[Read here](https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D) to see which methods are available for the ``ctx`` object.

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class ChartjsNode {
4949
global.document = window.document;
5050
global.window = window;
5151
const Chartjs = require('chart.js');
52+
if(configuration.options.plugins) {
53+
Chartjs.pluginService.register(configuration.options.plugins);
54+
}
5255
this._window = window;
5356
debug('got window');
5457
this._disableDynamicChartjsSettings(configuration);

0 commit comments

Comments
 (0)