<template>
<div class="com-container">
<div class="com-chart" ref="trend_ref"></div>
</div>
</template>
<script>
export default {
data() {
return {
chartInstane: null,
allData: null,
}
},
mounted() {
this.initChart()//初始化实例
this.getData()//获取数据
window.addEventListener('resize', this.screenAdapter)
this.screenAdapter() // 在页面加载完成的时候, 主动进行屏幕的适配
},
destroyed() {
window.removeEventListener('resize', this.screenAdapter)//取消监听事件
},
methods: {
// 初始化模块
initChart() {
/*
this.chartInstane = this.$echarts.init(this.$ref.trend_ref)//实例化
const initOption = {} //设置配置项
this.chartInstane.setOption(initOption) //把配置项给实力对象
*/
this.chartInstane = this.$echarts.init(this.$ref.trend_ref)
const initOption = {}
this.chartInstane.setOption(initOption)
},
//获取数据模块
async getData() {
// await this.$HTMLOutputElement.get()
// 对allData进行赋值
this.updateChart()//对数据进行处理
},
// 更新数据模块
updateChart() {
const dataOption = {}
this.chartInstane.setOption(dataOption)
},
// 更新对应分辨率模块
screenAdapter() {
const adapterOption = {}
this.chartInstane.setOption(adapterOption)
this.chartInstane.resize()
},
},
}
</script>
<style lang="less" scoped>
.com-container {
width: 100%;
height: 100%;
overflow: hidden;
.com-chart {
width: 100%;
height: 100%;
overflow: hidden;
}
}
</style>
vue2使用echarts通用代码结构
最新推荐文章于 2024-06-14 17:33:38 发布