`Uncaught TypeError: Cannot read property 'length' of null` (vuejs + chart.js)
See original GitHub issueHello,
I am trying to use Chart.js with vuejs. Unfortunately, I’m already blocked from trying out the “beginners” example’…
Here’s my Vue Component:
<template>
<canvas id="myChart" width="400" height="400"></canvas>
</template>
<script>
/*eslint-disable*/
import Chart from '../../node_modules/chart.js/src/Chart.js'
let ctx = document.getElementById("myChart")
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3]
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
export default {
name: 'dashboard',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
And the error I get:
Uncaught TypeError: Cannot read property 'length' of null
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (4 by maintainers)
Top Results From Across the Web
Chart Js Cannot read property 'length' of undefined
The problem is that when your code executes, the canvas has not been created yet. You should wrap your code inside a function...
Read more >Cannot read property 'length' of null"-Chart.js - appsloveworld
[Solved]-Problems with ChartJS "Uncaught TypeError: Cannot read property 'length' of null"-Chart. js. I believe that the answer is that the tag appears after ......
Read more >Uncaught Typeerror: Cannot Read Property 'Length' Of Null
This error indicates that our code expects to have an object with a length property but that object was not present. length is...
Read more >JS error:Cannot read property 'length' of undefined
JS error:Cannot read property 'length' of undefined; Debugging error in Google Charts · Ravi Panchumarthy · asgallant.
Read more >Uncaught TypeError cannot read property 'addeventlistener' of ...
In JavaScript, a very common error is the Uncaught TypeError Cannot read property 'addeventlistener' of null. This error occurs when JavaScript is not...
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 Free
Top 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
Oh I see,
<canvas>...</canvas>
need to be declared before<script>...</script>
👍
@HornKild read my last/previous comment. The error was due to the element not being present in the HTML when Chart.js was trying to attach the chart on it.