dl_site_system/dl_vue/src/views/dashboard/LineChart.vue

148 lines
3.1 KiB
Vue
Raw Normal View History

2025-06-19 09:43:36 +08:00
<template>
<div :class="className" :style="{height:height,width:width}" />
</template>
<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
export default {
mixins: [resize],
props: {
className: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '350px'
},
autoResize: {
type: Boolean,
default: true
},
chartData: {
type: Object,
required: true
}
},
data() {
return {
chart: null
}
},
watch: {
chartData: {
deep: true,
handler(val) {
this.setOptions(val)
}
}
},
mounted() {
this.$nextTick(() => {
this.initChart()
})
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
2025-07-17 16:08:15 +08:00
initChart(dataObj) {
2025-06-19 09:43:36 +08:00
this.chart = echarts.init(this.$el, 'macarons')
2025-07-17 16:08:15 +08:00
this.setOptions(dataObj)
2025-06-19 09:43:36 +08:00
},
2025-07-17 16:08:15 +08:00
setOptions(dataObj) {
2025-06-19 09:43:36 +08:00
this.chart.setOption({
xAxis: {
2025-07-17 16:08:15 +08:00
data: dataObj.month,
2025-06-19 09:43:36 +08:00
boundaryGap: false,
axisTick: {
show: false
}
},
grid: {
left: 10,
right: 10,
bottom: 20,
top: 30,
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
},
padding: [5, 10]
},
yAxis: {
axisTick: {
show: false
}
},
legend: {
2025-07-17 16:08:15 +08:00
data: ['总数', 'teams','whatsApp','email','在线询盘','在线聊天']
2025-06-19 09:43:36 +08:00
},
series: [{
2025-07-17 16:08:15 +08:00
name: '总数',
2025-06-19 09:43:36 +08:00
smooth: true,
type: 'line',
2025-07-17 16:08:15 +08:00
data: dataObj.allNum,
2025-06-19 09:43:36 +08:00
animationDuration: 2800,
animationEasing: 'cubicInOut'
},
{
2025-07-17 16:08:15 +08:00
name: 'teams',
2025-06-19 09:43:36 +08:00
smooth: true,
type: 'line',
2025-07-17 16:08:15 +08:00
data: dataObj.teamsNum,
2025-06-19 09:43:36 +08:00
animationDuration: 2800,
animationEasing: 'quadraticOut'
2025-07-17 16:08:15 +08:00
},
{
name: 'whatsApp',
smooth: true,
type: 'line',
data: dataObj.whatsAppNum,
animationDuration: 2800,
animationEasing: 'quadraticOut'
},
{
name: 'email',
smooth: true,
type: 'line',
data: dataObj.emailNum,
animationDuration: 2800,
animationEasing: 'quadraticOut'
},
{
name: '在线询盘',
smooth: true,
type: 'line',
data: dataObj.inquiryNum,
animationDuration: 2800,
animationEasing: 'quadraticOut'
},
{
name: '在线聊天',
smooth: true,
type: 'line',
data: dataObj.chatNum,
animationDuration: 2800,
animationEasing: 'quadraticOut'
}]
2025-06-19 09:43:36 +08:00
})
}
}
}
</script>