save chart instance on vm instance and add destroy() hooks to properly destroy chart when component is destroyed.

This commit is contained in:
Thorsten
2016-08-19 21:30:39 +02:00
parent 44eb15a89a
commit 998b190007
6 changed files with 30 additions and 12 deletions

View File

@@ -45,14 +45,17 @@ export default Vue.extend({
methods: {
render (data, options = this.options) {
const chart = new Chart(
this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'bar',
data: data,
options: options
}
)
chart.generateLegend()
this._chart.generateLegend()
}
},
destroy () {
this._chart.destroy()
}
})

View File

@@ -28,14 +28,17 @@ export default Vue.extend({
methods: {
render (data, options = this.options) {
const chart = new Chart(
this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'doughnut',
data: data,
options: options
}
)
chart.generateLegend()
this._chart.generateLegend()
}
},
destroy () {
this._chart.destroy()
}
})

View File

@@ -43,14 +43,17 @@ export default Vue.extend({
methods: {
render (data, options = this.options) {
const chart = new Chart(
this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'line',
data: data,
options: options
}
)
chart.generateLegend()
this._chart.generateLegend()
}
},
destroy () {
this._chart.destroy()
}
})

View File

@@ -28,14 +28,17 @@ export default Vue.extend({
methods: {
render (data, options = this.options) {
const chart = new Chart(
this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'pie',
data: data,
options: options
}
)
chart.generateLegend()
this._chart.generateLegend()
}
},
destroy () {
this._chart.destroy()
}
})

View File

@@ -28,14 +28,17 @@ export default Vue.extend({
methods: {
render (data, options = this.options) {
const chart = new Chart(
this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'polarArea',
data: data,
options: options
}
)
chart.generateLegend()
this._chart.generateLegend()
}
},
destroy () {
this._chart.destroy()
}
})

View File

@@ -28,14 +28,17 @@ export default Vue.extend({
methods: {
render (data, options = this.options) {
const chart = new Chart(
this._chart = new Chart(
this.$els.canvas.getContext('2d'), {
type: 'radar',
data: data,
options: options
}
)
chart.generateLegend()
this._chart.generateLegend()
}
},
destroy () {
this._chart.destroy()
}
})