Skip to content

Cannot read property 'length' of null #75

@sam13591980

Description

@sam13591980

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions