ReferenceError: HTMLCanvasElement is not defined
See original GitHub issueTrying to apply this library to code ported from the front end:
const ChartjsNode = require('chartjs-node')
let chart = new ChartjsNode(300, 200)
let result = require('./data.json')
let data = {
labels: result.map(d => d.date[ 2 ] + '-' + d.date[ 1 ]),
datasets: [
{
label: 'x',
backgroundColor: 'rgba(255, 99, 132, 0.7)',
borderColor: 'rgba(255, 99, 132, 0.7)',
data: result.map(d => d.x)
},
{
label: 'y',
backgroundColor: 'rgba(54, 162, 235, 0.7)',
borderColor: 'rgba(54, 162, 235, 0.7)',
data: result.map(d => d.y)
},
{
label: 'z',
backgroundColor: 'rgba(255, 206, 86, 0.7)',
borderColor: 'rgba(255, 206, 86, 0.7)',
data: result.map(d => d.z)
}
]
}
let options = {
fill: false,
legend: {
position: 'bottom'
},
elements: {
line: {
tension: 0,
fill: false
}
}
}
chart.drawChart({ type: 'line', data: data, options: options })
.then(() => {
chart.writeImageToFile('image/png', './chart.png')
chart.destroy()
})
.catch(error => console.log(error))
This results in ReferenceError: HTMLCanvasElement is not defined
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
In Next.js Error [ReferenceError: HTMLCanvasElement is not ...
js library like the code above. But when I run the code, I get the following error: ReferenceError: HTMLCanvasElement is not defined. error ......
Read more >HTMLCanvasElement.toDataURL() - Web APIs | MDN
The HTMLCanvasElement.toDataURL() method returns a data URL containing a representation of the image in the format specified by the type ...
Read more >How to test HTML5 canvas with jest? - Yonatan Kra
How to solve ReferenceError: Path2D is not defined. This error happens because Jest runs on JSDom and not in a real browser. Luckily,...
Read more >jest-canvas-mock - npm
Mock Strategy. This mock strategy implements all the canvas functions and actually verifies the parameters. If a known condition would cause ...
Read more >Writing Files with Node.js and JSDOM | by Danny Lee - Medium
Uncaught ReferenceError: require is not defined at index.js:1 ... /node_modules/jsdom/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js:42:5)
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Published an updated version
chartjs-node@1.1.1
with the updated peerDependency. Originally I hadchart.js
as a peerDependency because I wanted to give some flexibility on the version of chart.js you could use with this package 😕.We’ll see if we can figure out what’s going on with the newer versions of chart.js.
Not sure whats different in
chart.js@2.40
vschart.js@2.30
. To be honest that’s just the version I tested against and set CI up for. I’ll change thepeerDependencies
to usechart.js@2.3.*
. So that thenpm install
indicates an unmet dependency.Won’t have time to see what the deal is with 2.4.0. But I’ll open another issue to support it.