You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

119 lines
3.0 KiB

<template>
<div>
<div :id="idName" :style="{ height: height, width: width }" />
</div>
</template>
<script>
export default {
props: {
idName: { type: String, default: 'chart' },
width: { type: String, default: '100%' },
height: { type: String, default: '200px' },
chartData: { type: Array, default: () => [] },
desc: { type: String, default: '' }
},
data() {
return {
legendData: [],
seriesData: [],
disabled: false
}
},
watch: {
chartData: {
handler(val, olVal) {
console.log(val)
this.initFun()
},
deep: true
}
},
mounted() {
this.initFun()
},
methods: {
initFun() {
this.legendData = []
if (this.chartData && this.chartData.length > 0) {
this.chartData.forEach((item, index) => {
this.legendData.push(item.type)
item.dataList = []
item.dateList = []
item.echartsVo.forEach((iten, i) => {
item.dataList.push(iten.value)
item.dateList.push(iten.data)
if (index === this.chartData.length - 1 && i === item.echartsVo.length - 1) {
this.visionFun()
}
})
})
}
},
visionFun() {
// 基于准备好的dom,初始化echarts实例
const followUpBar = this.$echarts.init(document.getElementById(this.idName))
this.chartData.forEach(item => {
this.seriesData.push({
name: item.type,
type: 'line',
data: item.dataList
})
})
// 基于准备好的dom,初始化echarts实例
followUpBar.setOption({
tooltip: {
trigger: 'axis',
formatter: function(params, ticket, callback) {
let result = `${params[0].name} <br/>`
params.forEach(item => {
if (item.value) {
result += `${item.marker}${item.seriesName} : ${item.value}% <br/>`
} else {
result += `${item.marker}${item.seriesName} : - <br/>`
}
})
return result
}
},
legend: {
data: this.legendData,
top: 30
},
dataZoom: [
{
type: 'inside',
disabled: this.disabled,
start: 0,
end: 100
}
],
grid: {
top: 80,
left: 50,
right: 50,
bottom: 30,
containLabel: false
},
xAxis: {
type: 'category',
boundaryGap: false,
data: this.chartData[0].dateList
},
yAxis: {
type: 'value',
axisLabel: {
show: true,
interval: 'auto',
formatter: '{value}%'
}
},
series: [...this.seriesData]
})
window.addEventListener('resize', () => { followUpBar.resize() })
}
}
}
</script>
<style style="scss" scoped>
</style>