mirror of
https://github.com/KevinMidboe/vue-chartjs.git
synced 2025-10-29 18:00:20 +00:00
save chart instance on vm instance and add destroy() hooks to properly destroy chart when component is destroyed.
This commit is contained in:
@@ -45,14 +45,17 @@ export default Vue.extend({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (data, options = this.options) {
|
render (data, options = this.options) {
|
||||||
const chart = new Chart(
|
this._chart = new Chart(
|
||||||
this.$els.canvas.getContext('2d'), {
|
this.$els.canvas.getContext('2d'), {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: data,
|
data: data,
|
||||||
options: options
|
options: options
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
chart.generateLegend()
|
this._chart.generateLegend()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
destroy () {
|
||||||
|
this._chart.destroy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,14 +28,17 @@ export default Vue.extend({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (data, options = this.options) {
|
render (data, options = this.options) {
|
||||||
const chart = new Chart(
|
this._chart = new Chart(
|
||||||
this.$els.canvas.getContext('2d'), {
|
this.$els.canvas.getContext('2d'), {
|
||||||
type: 'doughnut',
|
type: 'doughnut',
|
||||||
data: data,
|
data: data,
|
||||||
options: options
|
options: options
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
chart.generateLegend()
|
this._chart.generateLegend()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
destroy () {
|
||||||
|
this._chart.destroy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -43,14 +43,17 @@ export default Vue.extend({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (data, options = this.options) {
|
render (data, options = this.options) {
|
||||||
const chart = new Chart(
|
this._chart = new Chart(
|
||||||
this.$els.canvas.getContext('2d'), {
|
this.$els.canvas.getContext('2d'), {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: data,
|
data: data,
|
||||||
options: options
|
options: options
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
chart.generateLegend()
|
this._chart.generateLegend()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
destroy () {
|
||||||
|
this._chart.destroy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,14 +28,17 @@ export default Vue.extend({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (data, options = this.options) {
|
render (data, options = this.options) {
|
||||||
const chart = new Chart(
|
this._chart = new Chart(
|
||||||
this.$els.canvas.getContext('2d'), {
|
this.$els.canvas.getContext('2d'), {
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
data: data,
|
data: data,
|
||||||
options: options
|
options: options
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
chart.generateLegend()
|
this._chart.generateLegend()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
destroy () {
|
||||||
|
this._chart.destroy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,14 +28,17 @@ export default Vue.extend({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (data, options = this.options) {
|
render (data, options = this.options) {
|
||||||
const chart = new Chart(
|
this._chart = new Chart(
|
||||||
this.$els.canvas.getContext('2d'), {
|
this.$els.canvas.getContext('2d'), {
|
||||||
type: 'polarArea',
|
type: 'polarArea',
|
||||||
data: data,
|
data: data,
|
||||||
options: options
|
options: options
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
chart.generateLegend()
|
this._chart.generateLegend()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
destroy () {
|
||||||
|
this._chart.destroy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,14 +28,17 @@ export default Vue.extend({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (data, options = this.options) {
|
render (data, options = this.options) {
|
||||||
const chart = new Chart(
|
this._chart = new Chart(
|
||||||
this.$els.canvas.getContext('2d'), {
|
this.$els.canvas.getContext('2d'), {
|
||||||
type: 'radar',
|
type: 'radar',
|
||||||
data: data,
|
data: data,
|
||||||
options: options
|
options: options
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
chart.generateLegend()
|
this._chart.generateLegend()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
destroy () {
|
||||||
|
this._chart.destroy()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user