Created
April 26, 2017 10:04
-
-
Save eirikb/2b12bd8bf8949a2051f115f141393240 to your computer and use it in GitHub Desktop.
Chart.js in Vue2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<canvas ref="chart"></canvas> | |
</template> | |
<script> | |
import chart from 'chart.js' | |
export default { | |
props: ['options', 'data'], | |
mounted() { | |
this.chart = new Chart(this.$refs.chart, this.options); | |
this.refresh(); | |
}, | |
methods: { | |
refresh() { | |
if (!this.chart || !this.data) return; | |
this.chart.config.data = this.data; | |
this.chart.update(); | |
} | |
}, | |
watch: { | |
data() { | |
this.refresh(); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment