Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'length' of null #75

Open
sam13591980 opened this issue Jul 24, 2019 · 3 comments
Open

Cannot read property 'length' of null #75

sam13591980 opened this issue Jul 24, 2019 · 3 comments

Comments

@sam13591980
Copy link

sam13591980 commented Jul 24, 2019

Hello,
I just simply installed this (also installed canvas as npm install canvas and chart.js as npm install chart.js) and used the following code. and I got the below error.

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 */
        }
    }
};
// xy is an array object as [{x:0,y:1},.....]
var chartJsOptions = {
    type: 'scatter',
    data: {datasets:[{data:xy}]},
    options: myChartOptions
};
const ChartjsNode = require('chartjs-node');
var chartNode = new ChartjsNode(600, 600);
chartNode.drawChart(chartJsOptions)
.then(() => {
    // chart is created

    // get image as png buffer
    return chartNode.getImageBuffer('image/png');
})
.then(buffer => {
    if(Array.isArray(buffer)) return chartNode.getImageStream('image/png');
})
.then(streamResult => {
    return chartNode.writeImageToFile('image/png', './testimage.png');
})
.then(() => {
    // chart is now written to the file path
    // ./testimage.png
});`
```
Unhandled rejection TypeError: Cannot read property 'length' of null
    at Object.acquireContext (x:\\node_modules\chart.js\dist\Chart.js:6896:19)
    at Chart.construct (x:\\node_modules\chart.js\dist\Chart.js:8415:26)
    at new Chart (x:\\node_modules\chart.js\dist\Chart.js:8402:7)
    at jsdom.envAsync.then.window (x:\\node_modules\chartjs-node\index.js:106:31)
    at tryCatcher (x:\\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (x:\\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (x:\\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (x:\\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (x:\\node_modules\bluebird\js\release\promise.js:694:18)
    at Promise._fulfill (x:\\node_modules\bluebird\js\release\promise.js:638:18)
    at Object.done (x:\\node_modules\bluebird\js\release\nodeback.js:42:21)
    at process.nextTick (x:\\node_modules\jsdom\lib\jsdom.js:320:18)
    at process._tickCallback (internal/process/next_tick.js:61:11)
@CoalSephos
Copy link

having the same issue

@chronosis
Copy link

JSDom is a secondary dependency of this project and the version included has a bug. You can fix this by installing JSDom directly.

npm install jsdom

@gjovanov
Copy link

This issue seems to be related to #42 ... It seems that canvas version 2+ doesn't work on Win. If you downgrade canvas to 1.6.13, it works for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants