<template>
|
<div class="echarts-box">
|
<div class="tab-scroll">
|
<PublicDataStandard :dataStandard="dataStandard"></PublicDataStandard>
|
<span class="time-select">{{ formData.startTime }}—{{ formData.endTime }}</span>
|
</div>
|
<div class="echarts-form">
|
<span class="demonstration">开始时间:</span>
|
<el-date-picker
|
v-model="formData.startTime"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
type="datetime">
|
</el-date-picker>
|
<span class="demonstration">结束时间:</span>
|
<el-date-picker
|
v-model="formData.endTime"
|
value-format="yyyy-MM-dd HH:mm:ss"
|
type="datetime">
|
</el-date-picker>
|
<span class="demonstration">采样点数:</span>
|
<el-select v-model="region" placeholder="请选择" style="width: 80px">
|
<el-option v-for="(item,index) in regionList" :key="index" :label="item" :value="item"></el-option>
|
</el-select>
|
<el-button @click="querySearch()">查询</el-button>
|
<el-button>明细表</el-button>
|
</div>
|
<div class="echarts-chart">
|
<div style="width:5rem;height:1.5rem;" ref="echarts"></div>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
|
import 'dayjs/locale/es'
|
import dayjs from 'dayjs'
|
|
import mapApi from '../../../api/mapApi'
|
import PublicDataStandard from '../PublicDataStandard'
|
|
export default {
|
name: 'ECharts',
|
components: {
|
PublicDataStandard
|
},
|
data () {
|
return {
|
a: '',
|
// tab栏传递接收数据
|
dataStandard: [
|
{
|
current: {
|
name: '氮氧化物',
|
val: 29.93
|
},
|
standard: {
|
name: '标准',
|
val: 100
|
}
|
},
|
{
|
current: {
|
name: '二氧化硫',
|
val: 17.34
|
},
|
standard: {
|
name: '标准',
|
val: 50
|
}
|
},
|
{
|
current: {
|
name: '烟尘',
|
val: 6.93
|
},
|
standard: {
|
name: '标准',
|
val: 30
|
}
|
},
|
{
|
current: {
|
name: '废气流量',
|
val: 120
|
},
|
standard: {
|
name: '',
|
val: null
|
}
|
}],
|
formData: {
|
startTime: dayjs().subtract(3, 'minute').format('YYYY-MM-DD HH:mm:ss'),
|
endTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
},
|
region: '25',
|
regionList: [25, 50, 75, 100],
|
datatype: 1,
|
RealTimeDataList: [],
|
bzz: null,
|
bzzList: [],
|
nameList: [],
|
// legend类别图表展示设置数组
|
lengList: [],
|
ydatas: []
|
}
|
},
|
mounted () {
|
this.$nextTick(() => {
|
this.initEchartsData()
|
})
|
},
|
methods: {
|
// 查询搜索功能
|
querySearch () {
|
this.initEchartsData()
|
},
|
async initEchartsData () {
|
const data = {
|
$tagCodeList: 'TJIP45.y2h508CEMS01NOX,CTJIP45.y2h508CEMS01SO2,CTJIP45.y2h508CEMS01F,CTJIP45.y2h508CEMS01PM',
|
$startTime: this.formData.startTime,
|
$endTime: this.formData.endTime,
|
$step: 15
|
}
|
const result = (await mapApi.getDataItems(data)).data
|
this.pointsSet(result)
|
this.legendSet()
|
this.yDataSet()
|
this.drawRealTimeDateChart()
|
},
|
// 接口数据按照 数据内分类别设置
|
pointsSet (d) {
|
let data = []
|
let datalist = []
|
for (let i = 0; i < d.length; i++) {
|
// this.RealTimeDataList = []
|
// 判断是否继续执行
|
if (d[i].ErrorMessage != null) {
|
continue
|
}
|
// temp 临时数据判断方法
|
const tempList = [
|
{
|
'TJIP45.lscl2tbAIA-10505-1': '氮氧化物',
|
'TJIP45.lscl2tbAIA-10505-2': '烟尘',
|
'TJIP45.lscl2tb552AISA11202A': '二氧化磷',
|
'TJIP45.lscl2tb552AISA11201B': 'pH',
|
'TJIP45.lscl2tb552AI10710': '二氧化碳'
|
}
|
]
|
// 指标
|
const name = tempList[0][d[i].UnionTagCode]
|
// 判断市局类型进行分组
|
if (this.nameList.length === 0) {
|
// 数组为空时
|
this.nameList.push(name)
|
// todo 用dayjs
|
const newDate = new Date(d[i].ReadTime)
|
data = {
|
name: name,
|
value: [newDate, d[i].TagValue]
|
}
|
datalist = {
|
name: name,
|
data: [data]
|
}
|
// console.log('1111111')
|
this.RealTimeDataList.push(datalist)
|
} else if (this.nameList.indexOf(name) < 0) {
|
// 没有指标时
|
this.nameList.push(name)
|
const newDate = new Date(d[i].ReadTime)
|
data = {
|
name: name,
|
value: [newDate, d[i].TagValue]
|
}
|
datalist = {
|
name: name,
|
data: [data]
|
}
|
// console.log('222222222')
|
this.RealTimeDataList.push(datalist)
|
} else if (i === d.length - 1) {
|
// 循环到最后
|
if (this.nameList.indexOf(name) < 0) {
|
this.nameList.push(name)
|
const newDate = new Date(d[i].ReadTime)
|
data = {
|
name: name,
|
value: [newDate, d[i].TagValue]
|
}
|
datalist = {
|
name: name,
|
data: [data]
|
}
|
// console.log('3333333')
|
this.RealTimeDataList.push(datalist)
|
} else {
|
const newDate = new Date(d[i].ReadTime)
|
data = {
|
name: name,
|
value: [newDate, d[i].TagValue]
|
}
|
// console.log('444444')
|
for (let k = 0; k < this.RealTimeDataList.length; k++) {
|
if (this.RealTimeDataList[k].name === name) {
|
this.RealTimeDataList[k].data.push(data)
|
}
|
}
|
}
|
} else {
|
const newDate = new Date(d[i].ReadTime)
|
data = {
|
name: name,
|
value: [newDate, d[i].TagValue]
|
}
|
for (let k = 0; k < this.RealTimeDataList.length; k++) {
|
if (this.RealTimeDataList[k].name === name) {
|
this.RealTimeDataList[k].data.push(data)
|
}
|
}
|
}
|
}
|
console.log(this.RealTimeDataList)
|
},
|
// legend类别图表展示设置数组
|
legendSet () {
|
this.lengList = []
|
let objTemp
|
for (let l = 0; l < this.nameList.length; l++) {
|
let obj
|
let IconUrl
|
if (this.nameList[l] === 'pH') {
|
IconUrl = 'image://../assets/imgs/legend/WenDu.png'
|
} else if (this.nameList[l] === '氮氧化物') {
|
IconUrl = 'image://../assets/imgs/legend/NOX.png'
|
} else if (this.nameList[l] === '烟尘') {
|
IconUrl = 'image://../assets/imgs/legend/zongdan.png'
|
} else if (this.nameList[l] === '二氧化碳') {
|
IconUrl = 'image://../assets/imgs/legend/YanChen.png'
|
} else if (this.nameList[l] === '二氧化磷') {
|
IconUrl = 'image://../assets/imgs/legend/VOCs.png'
|
}
|
if (this.nameList[l] === '废水' || this.nameList[l] === '废水流量') { // 将废水流量排到数组最后
|
objTemp = {
|
name: this.nameList[l],
|
icon: IconUrl,
|
textStyle: {
|
color: '#ccc'
|
},
|
itemWidth: 20,
|
itemHeight: 5
|
}
|
} else {
|
obj = {
|
name: this.nameList[l],
|
icon: IconUrl,
|
textStyle: {
|
color: '#ccc'
|
},
|
itemWidth: 20,
|
itemHeight: 5
|
}
|
this.lengList.push(obj)
|
}
|
}
|
this.lengList.push(objTemp)
|
},
|
// yDataSet 数据处理
|
yDataSet () {
|
this.bzzList = []
|
this.ydatas = []
|
for (let j = 0; j < this.nameList.length; j++) {
|
let zdcbcolor, zxcolor
|
if (this.nameList[j] === 'pH') {
|
zdcbcolor = 'red'
|
zxcolor = '#900090'
|
} else if (this.nameList[j] === '氨氮') {
|
zdcbcolor = 'red'
|
zxcolor = '#00B0F0'
|
} else if (this.nameList[j] === '烟尘') {
|
zdcbcolor = 'red'
|
zxcolor = '#f48183'
|
} else if (this.nameList[j] === '总氮') {
|
zdcbcolor = 'red'
|
zxcolor = '#e0ffff'
|
} else {
|
zdcbcolor = 'red'
|
zxcolor = '#9ACD32'
|
}
|
let ydata
|
|
// 临时数据
|
const BBZMAPPING = {
|
COD: 35,
|
pH: 9,
|
总氮: 15,
|
总磷: 0.3,
|
氨氮: 3
|
}
|
for (let m = 0; m < this.RealTimeDataList.length; m++) {
|
let stdValue = null
|
if (this.RealTimeDataList[m].name === this.nameList[j]) {
|
for (const p in BBZMAPPING) {
|
// console.log('p' + p)
|
this.a = p
|
stdValue = BBZMAPPING[this.RealTimeDataList[m].name]
|
}
|
// console.log(stdValue)
|
this.bzz = {
|
name: this.nameList[j],
|
bzhui: stdValue
|
}
|
ydata = {
|
name: this.nameList[j],
|
data: this.RealTimeDataList[m].data,
|
zdcbcolor: zdcbcolor,
|
zxcolor: zxcolor,
|
bzz: stdValue
|
}
|
// console.log(stdValue)
|
this.bzzList.push(this.bzz)
|
this.ydatas.push(ydata)
|
}
|
}
|
}
|
},
|
// 根据处理好的数组进行echarts图标的渲染
|
drawRealTimeDateChart () {
|
this.myChart = this.$echarts.init(this.$refs.echarts)
|
this.myChart.clear()
|
|
const legend = this.lengList
|
const yname = '浓度(mg/m³)'
|
const bzzList = this.bzzList
|
|
const serLists = []
|
|
for (let i = 0; i < this.ydatas.length; i++) {
|
const zdcbcolor = this.ydatas[i].zdcbcolor
|
const bz = this.ydatas[i].bzz
|
// console.log(bz)
|
let obj
|
if (bz) {
|
obj = {
|
name: this.ydatas[i].name,
|
// symbol:'circle', // 折点形状
|
// symbolSize: 3, //大小
|
smooth: true, // 直线 ,true 为曲线
|
itemStyle: {
|
normal: {
|
color: function (c) { // 根据value 显示不同的折点颜色
|
let biaozhuiz
|
for (let i = 0; i < bzzList.length; i++) {
|
if (bzzList[i].name === c.seriesName) {
|
biaozhuiz = bzzList[i].bzhui
|
}
|
}
|
if (c.value[1] > biaozhuiz) {
|
return zdcbcolor
|
} else if (c.value[1] > biaozhuiz * 0.9) {
|
return '#FFA500'
|
} else {
|
return '#33c95f'
|
}
|
},
|
lineStyle: { // 折线的颜色
|
color: this.ydatas[i].zxcolor,
|
width: 2
|
},
|
// borderColor:'black', //折点边框的颜色
|
label: { // 显示值
|
show: false
|
}
|
}
|
},
|
type: 'line',
|
data: this.ydatas[i].data,
|
markLine: { // 平均值 , 和 指标上限
|
symbol: 'none',
|
data: [{
|
label: {
|
normal: {
|
position: 'end',
|
formatter: bz
|
}
|
},
|
name: '标准值',
|
yAxis: bz,
|
lineStyle: {
|
normal: {
|
color: function (c) { // 根据value 显示不同的折点颜色
|
let biaozhuiz
|
for (let i = 0; i < bzzList.length; i++) {
|
if (bzzList[i].name === c.seriesName) {
|
biaozhuiz = bzzList[i].bzhui
|
}
|
}
|
if (c.value[1] > biaozhuiz) {
|
return zdcbcolor
|
} else if (c.value[1] > biaozhuiz * 0.9) {
|
return '#FFA500'
|
} else {
|
return '#33c95f'
|
}
|
}
|
}
|
}
|
}
|
]
|
}
|
}
|
} else {
|
obj = {
|
name: this.ydatas[i].name,
|
symbol: 'circle', // 折点形状
|
symbolSize: 10, // 大小
|
smooth: false, // 直线 ,true 为曲线
|
yAxisIndex: 1,
|
// itemStyle: {
|
// normal: {
|
// color: function (c) { // 根据value 显示不同的折点颜色
|
// for (let i = 0; i < this.bzzList.length; i++) {
|
// let biaozhuizs
|
// if (this.bzzList[i].name === c.seriesName) {
|
// biaozhuizs = this.bzzList[i].bzhui
|
// }
|
// console.log(biaozhuizs)
|
// }
|
// if (c.value[1] > 9) {
|
// return zdcbcolor
|
// } else {
|
// return '#33c95f'
|
// }
|
// },
|
// lineStyle: { // 折线的颜色
|
// color: this.ydatas[i].zxcolor,
|
// width: 5
|
// },
|
// borderColor: 'black', // 折点边框的颜色
|
// label: { // 显示值
|
// show: false
|
// }
|
// }
|
// },
|
type: 'line',
|
data: this.ydatas[i].data
|
}
|
}
|
if (this.ydatas[i].name === '废气流量' || this.ydatas[i].name === '废气') {
|
obj.yAxisIndex = 1
|
}
|
serLists.push(obj)
|
}
|
// console.log(serLists)
|
let dataUnit = ''
|
if (this.datatype === 1) {
|
dataUnit = '流量(m³/d)'
|
} else {
|
dataUnit = '流量(m³/h)'
|
}
|
// echarts图表option数据
|
const options = {
|
tooltip: { // 提示框
|
trigger: 'axis',
|
axisPointer: {
|
type: 'cross',
|
label: {
|
color: '#1a4245'
|
}
|
},
|
formatter: function (params) {
|
let s = params[0].name + '<br />'
|
for (let i = 0; i < params.length; i++) {
|
// let name = params[i].name
|
// 图表title名称
|
const seriesName = params[i].seriesName
|
// 值
|
const value = params[i].value[1]
|
|
// const valueFliter = formatter(value)
|
const valueFliter = parseFloat(value).toFixed(2)
|
|
let maker = params[i].marker
|
let colo = ''
|
switch (seriesName) {
|
case 'pH':
|
colo = '#900090'
|
break
|
case '二氧化碳':
|
colo = '#00B0F0'
|
break
|
case '烟尘':
|
colo = '#e0ffff'
|
break
|
case '氮氧化物':
|
colo = '#9ACD32'
|
break
|
case '二氧化磷':
|
colo = '#f48183'
|
break
|
default:
|
colo = ''
|
break
|
}
|
maker = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:' + colo + ';"></span>'
|
s += maker + seriesName + ':' + valueFliter + '<br />'
|
}
|
return s
|
}
|
},
|
toolbox: { // 打印等工具
|
show: false,
|
feature: {
|
saveAsImage: {}
|
}
|
},
|
grid: { // 网格
|
top: '20%'
|
},
|
legend: {
|
data: legend
|
},
|
dataZoom: [{
|
type: 'inside',
|
start: 0,
|
end: 100
|
}, {
|
start: 0,
|
end: 100,
|
show: false,
|
handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
|
handleSize: '80%',
|
handleStyle: {
|
color: '#fff',
|
shadowBlur: 3,
|
shadowColor: 'rgba(0, 0, 0, 0.6)',
|
shadowOffsetX: 2,
|
shadowOffsetY: 2
|
}
|
}],
|
xAxis: { // x 轴设置
|
type: 'time',
|
boundaryGap: false,
|
axisLabel: { // x轴全部显示
|
// rotate: 30,
|
margin: 6,
|
interval: 0,
|
textStyle: {
|
color: '#fff'
|
}
|
},
|
splitLine: { // 网格垂直线为 虚线
|
show: true,
|
lineStyle: {
|
type: 'dashed'
|
}
|
},
|
axisTick: { // x 轴刻度显示
|
show: false
|
},
|
axisLine: {
|
lineStyle: {
|
color: '#FFFFFF',
|
width: 1// 这里是为了突出显示加上的
|
}
|
}
|
// data: xdata
|
},
|
yAxis: [{
|
type: 'value',
|
name: yname,
|
max: function (value) {
|
return parseInt(value.max + 30)
|
},
|
axisLabel: {
|
formatter: '{value}',
|
textStyle: {
|
color: '#fff'
|
}
|
},
|
axisPointer: {
|
snap: true
|
},
|
splitLine: {
|
show: false
|
}, // y轴 网格线不显示,
|
axisLine: {
|
lineStyle: {
|
color: '#FFFFFF',
|
width: 1// 这里是为了突出显示加上的
|
}
|
}
|
}, {
|
type: 'value',
|
name: dataUnit,
|
axisLabel: {
|
formatter: '{value}',
|
textStyle: {
|
color: '#fff'
|
}
|
},
|
axisPointer: {
|
snap: true
|
},
|
splitLine: {
|
show: false
|
}, // y轴 网格线不显示,
|
// inverse: true,
|
// nameLocation: 'start',
|
// max:500,
|
axisLine: {
|
lineStyle: {
|
color: '#FFFFFF',
|
width: 1// 这里是为了突出显示加上的
|
}
|
}
|
}],
|
series: serLists
|
}
|
this.myChart.setOption(options, true)
|
console.log(options)
|
window.onresize = this.myChart.resize
|
}
|
}
|
}
|
</script>
|
|
<style scoped lang="less">
|
.echarts-box {
|
.tab-scroll {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
|
.time-select {
|
cursor: pointer;
|
padding: 5px;
|
border: 1px solid #2b87c8;
|
border-radius: 4px;
|
text-align: center;
|
color: #fff;
|
font-size: 11px;
|
width: 280px;
|
}
|
}
|
|
.echarts-form {
|
height: 0.3rem;
|
line-height: 0.3rem;
|
|
.demonstration {
|
color: #00fff6;
|
font-size: 12px;
|
margin-left: 10px;
|
}
|
|
/deep/ .el-input__inner {
|
height: 0.15rem;
|
background-color: #2e4967;
|
color: #fff;
|
font-size: 12px;
|
padding: 0;
|
border-color: #00fff6;
|
text-align: center;
|
}
|
|
.el-button {
|
margin: 0 15px;
|
width: 0.3rem;
|
height: 0.15rem;
|
display: inline-block;
|
background-color: #2e4967;
|
color: #fff;
|
font-size: 12px;
|
padding: 0;
|
border-color: #00fff6;
|
text-align: center;
|
}
|
}
|
|
/deep/ .el-icon-time:before {
|
content: " ";
|
}
|
}
|
</style>
|