yudao-dev/src/views/databoard/components/FlueGasChart.vue

262 lines
5.1 KiB
Vue
Raw Normal View History

2024-01-03 14:08:49 +08:00
<template>
2024-01-11 13:44:38 +08:00
<div>
<NotMsg v-show="notMsg"/>
<div id='flueGasChart' class="flue-gas-chart" style="width:575px;height:250px;" v-show='!notMsg'></div>
2024-01-11 13:44:38 +08:00
</div>
2024-01-03 14:08:49 +08:00
</template>
<script>
2024-01-17 09:11:02 +08:00
import * as echarts from 'echarts'
2024-01-03 14:08:49 +08:00
import resize from './../mixins/resize'
2024-01-11 13:44:38 +08:00
import NotMsg from './../components/NotMsg'
2024-01-03 14:08:49 +08:00
export default {
2024-01-11 13:44:38 +08:00
name: 'FlueGasChart',
2024-01-03 14:08:49 +08:00
mixins: [resize],
2024-01-11 13:44:38 +08:00
components:{ NotMsg },
2024-01-03 14:08:49 +08:00
props: {
chartType: '',
chartTime: ''
},
data() {
const colors = [
'#12FFF5',
'#2760FF',
'#FFD160',
'#E80091',
'#8064ff',
'#ff8a3b',
'#8cd26d',
'#2aa1ff',
];
return {
2024-01-11 13:44:38 +08:00
chart: null,
notMsg:false
2024-01-03 14:08:49 +08:00
};
},
computed: {
gasChartDayTrend() {
return this.$store.state.websocket.gasChartDayTrend
},
gasChartWeekTrend() {
return this.$store.state.websocket.gasChartWeekTrend
},
gasChartMonthTrend() {
return this.$store.state.websocket.gasChartMonthTrend
},
gasChartYearTrend() {
return this.$store.state.websocket.gasChartYearTrend
}
},
watch: {
gasChartDayTrend: {
handler(newVal, oldVal) {
if (this.chartTime === '日') {
this.updateChart()
2024-01-18 14:05:39 +08:00
this.$emit('emitFun')
2024-01-03 14:08:49 +08:00
}
}
},
gasChartWeekTrend: {
handler(newVal, oldVal) {
if (this.chartTime === '周') {
this.updateChart()
2024-01-18 14:05:39 +08:00
this.$emit('emitFun')
2024-01-03 14:08:49 +08:00
}
}
},
gasChartMonthTrend: {
handler(newVal, oldVal) {
if (this.chartTime === '月') {
this.updateChart()
2024-01-18 14:05:39 +08:00
this.$emit('emitFun')
2024-01-03 14:08:49 +08:00
}
}
},
gasChartYearTrend: {
handler(newVal, oldVal) {
if (this.chartTime === '年') {
this.updateChart()
2024-01-18 14:05:39 +08:00
this.$emit('emitFun')
2024-01-03 14:08:49 +08:00
}
}
},
chartType: {// 监听类型变化,更新图
handler(newVal, oldVal) {
this.updateChart()
}
},
chartTime: {// 监听时间变化,更新图
handler(newVal, oldVal) {
this.updateChart()
}
}
},
mounted() {
this.$el.addEventListener('resize', () => {
console.log('resziing.....');
});
this.updateChart()
},
methods: {
updateChart() {
let gasName = ''
const colors = ['#FFCB59'];
let temp1 = []
let temp2 = []
let seriesData = []
let xData = []
let yData = []
switch (this.chartTime) {
case '日':{
temp1 = this.gasChartDayTrend
break;
}
case '周':{
temp1 = this.gasChartWeekTrend
break;
}
case '月':{
temp1 = this.gasChartMonthTrend
break;
}
case '年':{
temp1 = this.gasChartYearTrend
break;
}
default:
}
switch (this.chartType) {
case '氧气含量':{
2024-01-08 16:59:42 +08:00
temp2 = temp1?.O2_float || []
2024-01-03 14:08:49 +08:00
break;
}
case '二氧化硫':{
2024-01-08 16:59:42 +08:00
temp2 = temp1?.SO2_float || []
2024-01-03 14:08:49 +08:00
break;
}
2024-01-12 09:45:36 +08:00
case '氮氧化物':{
2024-01-08 16:59:42 +08:00
temp2 = temp1?.NOX_float || []
2024-01-03 14:08:49 +08:00
break;
}
case '颗粒物':{
2024-01-08 16:59:42 +08:00
temp2 = temp1?.dust_float || []
2024-01-03 14:08:49 +08:00
break;
}
default:
}
2024-01-11 13:44:38 +08:00
if (temp2.length === 0) {
this.notMsg = true
return
} else {
this.notMsg = false
}
temp2.map(i => {
2024-01-03 14:08:49 +08:00
xData.push(i.time)
yData.push((i.value)?(Number(i.value)).toFixed(2):null)
})
2024-01-03 14:08:49 +08:00
if (yData.length == 0) {
seriesData = []
}else {
seriesData = [{
name: gasName,
data: yData,
type: "line",
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#FFCB59' + "40" },
{ offset: 0.5, color: '#FFCB59' + "20" },
{ offset: 1, color: '#FFCB59' + "00" },
]),
},
lineStyle: {
width: 1
},
2024-01-17 09:11:02 +08:00
symbol: 'circle',
symbolSize: 5,
2024-01-03 14:08:49 +08:00
emphasis: {
focus: 'series'
}
}]
}
// 绘图
if (
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose() // 页面多次刷新会出现警告Dom已经初始化了一个实例这是销毁实例
}
2024-01-11 13:44:38 +08:00
this.chart = echarts.init(document.getElementById('flueGasChart'));
2024-01-03 14:08:49 +08:00
var option = {
color: colors,
2024-01-12 09:45:36 +08:00
grid: { top: 32, right: 12, bottom: 20, left: 60 },
2024-01-03 14:08:49 +08:00
xAxis: {
type: 'category',
data: xData,
axisLabel: {
color: '#fff',
fontSize: 12,
},
axisTick: { show: false },
axisLine: {
lineStyle: {
width: 1,
color: '#213259',
},
},
},
yAxis: {
2024-01-11 13:44:38 +08:00
name: this.chartType === '氧气含量' ? '单位%':'单位mg/m³',
2024-01-03 14:08:49 +08:00
nameTextStyle: {
color: '#fff',
fontSize: 10,
align: 'right',
},
type: 'value',
axisLabel: {
color: '#fff',
fontSize: 12,
},
axisLine: {
show: true,
lineStyle: {
color: '#213259',
},
},
splitLine: {
lineStyle: {
color: '#213259a0',
},
},
},
series: seriesData,
tooltip: {
trigger: 'axis',
2024-01-11 13:44:38 +08:00
className: "gas-chart-tooltip"
2024-01-03 14:08:49 +08:00
},
}
option && this.chart.setOption(option)
}
},
};
</script>
<style scoped lang="scss">
2024-01-11 13:44:38 +08:00
.flue-gas-chart {
2024-01-03 14:08:49 +08:00
width: 100%;
height: 100%;
}
</style>
2024-01-11 13:44:38 +08:00
<style>
.gas-chart-tooltip {
background: #0a2b4f77 !important;
border: none !important;
backdrop-filter: blur(12px);
}
.gas-chart-tooltip * {
color: #fff !important;
}
</style>