this.$refs doesn't seem to have expected canvas property
See original GitHub issueExpected Behavior
Expect the example chart to render in the browser.
Actual Behavior
Error in console and nothing renders to the page.
Error occurs in the Bar
[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'getContext' of undefined"
TypeError: Cannot read property 'getContext' of undefined
at VueComponent.renderChart (Bar.js?7b87:78)
at VueComponent.boundFn [as renderChart] (vue.runtime.esm.js?ff9b:182)
at VueComponent.mounted (win-ew-pie-chart.vue?6dcc:15)
at callHook (vue.esm.js?efeb:2665)
at Object.insert (vue.esm.js?efeb:3526)
at invokeInsertHook (vue.esm.js?efeb:5469)
at Vue$3.patch [as __patch__] (vue.esm.js?efeb:5639)
at Vue$3.Vue._update (vue.esm.js?efeb:2414)
at Vue$3.updateComponent (vue.esm.js?efeb:2538)
at Watcher.get (vue.esm.js?efeb:2881)
My Vue Component
<template>
<div class="app">
</div>
</template>
<script>
import { Bar } from 'vue-chartjs'
// console.log(Bar)
export default Bar.extend({
mounted () {
// Overwriting base render method with actual data.
this.renderChart({
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
datasets: [
{
label: 'GitHub Commits',
backgroundColor: '#f87979',
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
}
]
})
}
})
</script>
<style lang="css">
</style>
Environment
- vue.js version: 2.4.2
- vue-chart.js version: 2.7.2
- webpack version: 3.3.0
- yarn version: 0.27.5
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Vue3 TypeError: template ref.value is null - Stack Overflow
So I have to do something after initialization, right? Here is my code: <template> <canvas ref="chartRef" /> ...
Read more >How to use React createRef - LogRocket Blog
Learn how to use the React.createRef() method and useRef Hook in React to simplify creating refs and interact with the HTML DOM.
Read more >The Embed Audio element - HTML - MDN Web Docs - Mozilla
This enumerated attribute indicates whether to use CORS to fetch the related audio file. CORS-enabled resources can be reused in the <canvas> ...
Read more >The Book Thief - SharpSchool
I've seen more eclipses than I care to remember. ... The Hubermanns lived in one of the small, boxlike houses on Himmel Street....
Read more >Three Insights I Gained While Researching Vue.js Accessibility
Web app accessibility appears difficult because it seems that there is little information on the subject available online. Let's take a ...
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
You have to remove the template part of your component.
You are extending the baseChart component, which comes with a template. If you keep the
you overwrite everything from the base chart, as templates can not be merged properly.
Just modify the template like this , may fixed the error
<template>
<div class="container">
<canvas ref="canvas" width="900" height="400"></canvas>
</div>
</template>