MixChart.vue 1.61 KB
<template>
    <div :id="id" :class="className" :style="{ height: height, width: width }"></div>
</template>

<script>
import echarts from 'echarts'
export default {
    props: {
        id: {
            type: String,
            default: 'chart'
        },
        className: {
            type: String,
            default: 'chart'
        },
        width: {
            type: String,
            default: '200px'
        },
        height: {
            type: String,
            default: '200px'
        },
        xData: {
            type: [Object, Array],
            default: {}
        },
        yData: {
            type: [Object, Array],
            default: {}
        },
        tooltip: {
            type: Object,
            default: {}
        },
        series: {
            type: [Object, Array],
            default: []
        },
        chartOption: {
            type: Object,
            default: {}
        }
    },
    data() {
        return {
            chart: null
        }
    },
    watch: {
        chartOption: {
            handler: 'drawChart',
            deep: true
        }
    },
    mounted() {
        this.initChart()
    },
    beforeDestory() {
        if(!this.chart) {
            return;
        }
        this.chart.dispose()
        this.chart = null
    },
    methods: {
        initChart() {
            this.chart = echarts.init(document.getElementById(this.id))

            this.chart.setOption()
        },
        drawEmpty() {
            // 无数据
        },
        drawChart(option) {
            this.chart.setOption(option)
        }
    }

}
</script>

<style>

</style>