DemuMesDataV/lib/components/charts/src/main.vue

65 lines
1.1 KiB
Vue
Raw Normal View History

2019-08-22 14:41:07 +08:00
<template>
<div class="dv-charts-container" :ref="ref">
<div class="charts-canvas-container" :ref="chartRef" />
</div>
</template>
<script>
import autoResize from '../../../mixin/autoResize'
import Charts from '@jiaminghi/charts'
export default {
name: 'DvCharts',
mixins: [autoResize],
props: {
option: {
type: Object,
default: () => ({})
}
},
data () {
2019-09-10 15:14:12 +08:00
const timestamp = Date.now()
2019-08-22 14:41:07 +08:00
return {
2019-09-10 15:14:12 +08:00
ref: `charts-container-${timestamp}`,
chartRef: `chart-${timestamp}`,
2019-08-22 14:41:07 +08:00
chart: null
}
},
watch: {
option () {
let { chart, option } = this
if (!chart) return
if (!option) option = {}
chart.setOption(option)
}
},
methods: {
afterAutoResizeMixinInit () {
const { initChart } = this
initChart()
},
initChart () {
const { $refs, chartRef, option } = this
const chart = this.chart = new Charts($refs[chartRef])
if (!option) return
chart.setOption(option)
},
onResize () {
const { chart } = this
if (!chart) return
chart.resize()
}
}
}
</script>