You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am current using using Chart.js 3.9.1. I was having a problem with chartjs-plugin-datalabels not working correctly after an initial call of 'new ChartJSNodeCanvas'. Digging through the chartjs-plugin-datalabels code I found there was an issue with 'instanceof' not working correctly on the subsequent calls. In my code, every call to my graphing method called 'new ChartJSNodeCanvas'. I was able to work around the issue by making a single global call to 'new ChartJSNodeCanvas' in my module and reusing it. It also had the side benefit of reducing the overhead of creating new canvases.
I reported the issue to the chartjs-plugin-datalabels maintainer and I was pointed to a similar issue at chartjs/chartjs-plugin-datalabels#251. Reading through the thread it seems there is a minor change needed to the Chart.js require statement to fix the issue. I edited line 149 of the chartjs-node-canvas index.js and changed
const chartJs = require('chart.js');
to
const chartJs = require('chart.js/auto');
With this change, my original code works fine. I will probably leave my code with the single global call as it does reduce the overhead of creating multiple canvases. But this change to the require statement appears to be something needed with the 3.x.x Chart.js to register the controllers, elements, scales and plugins you are going to use, as documented at https://www.chartjs.org/docs/latest/getting-started/integration.html.
The text was updated successfully, but these errors were encountered:
I am current using using Chart.js 3.9.1. I was having a problem with chartjs-plugin-datalabels not working correctly after an initial call of 'new ChartJSNodeCanvas'. Digging through the chartjs-plugin-datalabels code I found there was an issue with 'instanceof' not working correctly on the subsequent calls. In my code, every call to my graphing method called 'new ChartJSNodeCanvas'. I was able to work around the issue by making a single global call to 'new ChartJSNodeCanvas' in my module and reusing it. It also had the side benefit of reducing the overhead of creating new canvases.
I reported the issue to the chartjs-plugin-datalabels maintainer and I was pointed to a similar issue at chartjs/chartjs-plugin-datalabels#251. Reading through the thread it seems there is a minor change needed to the Chart.js require statement to fix the issue. I edited line 149 of the chartjs-node-canvas index.js and changed
const chartJs = require('chart.js');
to
const chartJs = require('chart.js/auto');
With this change, my original code works fine. I will probably leave my code with the single global call as it does reduce the overhead of creating multiple canvases. But this change to the require statement appears to be something needed with the 3.x.x Chart.js to register the controllers, elements, scales and plugins you are going to use, as documented at https://www.chartjs.org/docs/latest/getting-started/integration.html.
The text was updated successfully, but these errors were encountered: