Skip to content

Instantly share code, notes, and snippets.

@eirikb
Created April 26, 2017 10:04
Show Gist options
  • Save eirikb/2b12bd8bf8949a2051f115f141393240 to your computer and use it in GitHub Desktop.
Save eirikb/2b12bd8bf8949a2051f115f141393240 to your computer and use it in GitHub Desktop.
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