2👍
I faced this issue as well, I managed to fix it like this:
This is an example for the chartjs-plugin-annotation
What I forgot was to register the plugin in the beforeDraw
event
const ChartjsNode = require('chartjs-node');
const ChartjsAnnotation = require('chartjs-plugin-annotation');
var chartNode = new ChartjsNode(width, height);
chartNode.on('beforeDraw', function (Chartjs) {
// Register the annotation plugin
Chartjs.plugins.register( ChartjsAnnotation );
});
chartNode.drawChart( <your_chartjs_configuration> )
.then( function(){
// Save as testimage.png
chartNode.writeImageToFile('image/png', './testimage.png');
});
And your configuration (example):
type: 'line',
data: {
...
},
options: {
...
annotation: {
annotations: [{
value: 100,
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
borderColor: '#D2DAE2',
borderWidth: 1,
borderDash: [2, 2],
label: {
content: 'Value 1'
}
}, {
value: 50
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
borderColor: '#D2DAE2',
borderWidth: 1,
borderDash: [2, 2],
value: 500,
label: {
content: 'Value 2'
}
}]
}
- Chartjs-Chart.js the point's limit supported
- Chartjs-How to get radar chart coordinates using getValueForDistanceFromCenter with Chart.js?
Source:stackexchange.com