Skip to content

Instantly share code, notes, and snippets.

@eirikb eirikb/Chart.vue
Created Apr 26, 2017

Embed
What would you like to do?
Chart.js in Vue2
<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
You can’t perform that action at this time.