Commit f96e9363 authored by wends's avatar wends

fix g2line performance issue

parent 9ac6b3f2
<template> <template>
<div :ref="id" style="height: 100%;width: 100%" /> <div :id="id" style="height: 100%;width: 100%" />
</template> </template>
<script> <script>
...@@ -32,13 +32,25 @@ export default { ...@@ -32,13 +32,25 @@ export default {
} }
}, },
watch: { watch: {
title: function(val) {
this.line.updateConfig({
title: {
visible: true,
text: val
},
description: {
visible: true,
text: `单位为: ${this.description}`
}
})
this.line.render()
},
lineData: function(val) { lineData: function(val) {
this.line.changeData(val) this.line.changeData(val)
} }
}, },
mounted() { mounted() {
const el = this.$refs[this.id] this.line = new Line(document.getElementById(this.id), {
this.line = new Line(el, {
data: this.lineData, data: this.lineData,
title: { title: {
visible: true, visible: true,
...@@ -57,7 +69,13 @@ export default { ...@@ -57,7 +69,13 @@ export default {
crosshairs: { crosshairs: {
type: 'y' type: 'y'
}, },
offset: 20 offset: 20,
formatter: (x, y) => {
return {
name: this.title,
value: `${y} ${this.description}`
}
}
}, },
description: { description: {
visible: true, visible: true,
...@@ -74,6 +92,9 @@ export default { ...@@ -74,6 +92,9 @@ export default {
] ]
}) })
this.line.render() this.line.render()
},
beforeDestroy() {
this.line.destroy()
} }
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment