Skip to content

Commit 176929c

Browse files
ruimgoncalvesfundon
authored andcommitted
Update Chartjs.vue
Added support for plugins
1 parent 65ee0bc commit 176929c

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/Chartjs.vue

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ export default {
2525
options: {
2626
type: Object,
2727
default: () => ({})
28+
},
29+
plugins: {
30+
type: [Object, Array],
31+
default: () => ({})
2832
}
2933
},
3034
3135
mounted () {
32-
this.chart = new Chart(this.$el, {
33-
type: this.type,
34-
data: this.data,
35-
options: this.options
36-
})
36+
this.resetChart()
3737
},
3838
3939
data () {
@@ -44,33 +44,34 @@ export default {
4444
4545
methods: {
4646
resetChart () {
47-
this.$nextTick(() => {
47+
if (this.chart)
4848
this.chart.destroy()
49-
this.chart = new Chart(this.$el, {
50-
type: this.type,
51-
data: this.data,
52-
options: this.options
53-
})
49+
50+
this.chart = new Chart(this.$el, {
51+
type: this.type,
52+
data: this.data,
53+
options: this.options,
54+
plugins: this.plugins
5455
})
5556
}
5657
},
5758
5859
watch: {
5960
type () {
60-
this.resetChart()
61+
this.$nextTick(() => this.resetChart())
6162
},
6263
data () {
6364
this.chart.update()
6465
},
6566
options () {
66-
this.resetChart()
67+
this.$nextTick(() => this.resetChart())
6768
}
6869
}
6970
}
7071
</script>
7172

7273
<style lang="scss">
73-
canvas.chartjs {
74-
max-width: 100%;
75-
}
74+
canvas.chartjs {
75+
max-width: 100%;
76+
}
7677
</style>

0 commit comments

Comments
 (0)