From 17de93255772734b15cce7a0c680a40d2ec5878c Mon Sep 17 00:00:00 2001 From: zhangshuaibao <15731629597@163.com> Date: 星期五, 09 四月 2021 09:43:43 +0800 Subject: [PATCH] echarts日数据折线图实现 --- src/components/BaseNav/PublicBounced/GasComponents/EChartsHour.vue | 312 +++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 234 insertions(+), 78 deletions(-) diff --git a/src/components/BaseNav/PublicBounced/GasComponents/EChartsHour.vue b/src/components/BaseNav/PublicBounced/GasComponents/EChartsHour.vue index 49744bd..9ecea2e 100644 --- a/src/components/BaseNav/PublicBounced/GasComponents/EChartsHour.vue +++ b/src/components/BaseNav/PublicBounced/GasComponents/EChartsHour.vue @@ -2,20 +2,28 @@ <template> <div id="Tab"> <div class="infomation"> - <el-tag>姘哀鍖栫墿 : 29.93 鏍囧噯 : 100</el-tag> - <el-tag>浜屾哀鍖栫~ : 17.34 鏍囧噯 : 50</el-tag> - <el-tag>鐑熷皹 : 6.93 鏍囧噯 : 30</el-tag> - <el-tag>搴熸皵娴侀噺 : 120343.18</el-tag> +<!-- <el-tag>姘哀鍖栫墿 : 29.93 鏍囧噯 : 100</el-tag>--> +<!-- <el-tag>浜屾哀鍖栫~ : 17.34 鏍囧噯 : 50</el-tag>--> +<!-- <el-tag>鐑熷皹 : 6.93 鏍囧噯 : 30</el-tag>--> +<!-- <el-tag>搴熸皵娴侀噺 : 120343.18</el-tag>--> + <el-row> + <el-col :span="6"><div class="grid-content bg-purple">姘哀鍖栫墿 : 29.93 鏍囧噯 : 100</div></el-col> + <el-col :span="6"><div class="grid-content bg-purple">浜屾哀鍖栫~ : 17.34 鏍囧噯 : 50</div></el-col> + <el-col :span="6"><div class="grid-content bg-purple">鐑熷皹 : 6.93 鏍囧噯 : 30</div></el-col> + <el-col :span="6"><div class="grid-content bg-purple">搴熸皵娴侀噺 : 120343.18</div></el-col> +<!-- <el-col :span="6"><div class="grid-content bg-purple"></div></el-col>--> + </el-row> </div> <div class="form-echrts"> <!-- :title="this.$attrs.getWasteGasDetails[0].OnLineMonEmissPointName" --> -<!-- <div class="from-search">--> + <div class="from-search"> <!-- <el-form :inline="true" :model="formInline" class="demo-form-inline">--> -<!--<!– <el-form-item label="瀹℃壒浜�">–>--> -<!--<!– <el-input v-model="formInline.user" placeholder="瀹℃壒浜�"></el-input>–>--> -<!--<!– </el-form-item>–>--> +<!-- <el-form-item label="瀹℃壒浜�">--> +<!-- <el-input v-model="formInline.user" placeholder="瀹℃壒浜�"></el-input>--> +<!-- </el-form-item>--> <!-- <div class="block">--> <!-- <el-date-picker--> +<!-- size="'mini"--> <!-- class="date"--> <!-- v-model="value"--> <!-- type="datetimerange"--> @@ -36,21 +44,80 @@ <!-- <el-form-item>--> <!-- <el-button type="primary" @click="onSubmit">鏌ヨ</el-button>--> <!-- </el-form-item>--> + <!-- </el-form>--> -<!-- <el-button size="mini" round @click="dialogVisible = true">鏄庣粏琛�</el-button>--> -<!-- <el-dialog :visible.sync="dialogVisible"--> -<!-- :append-to-body="true"--> -<!-- :title="this.$attrs.value==='feiqi'?this.$attrs.getWasteGasDetails[0].OnLineMonEmissPointName:this.$attrs.getWasteWaterMonitoringDetails[0].OnLineMonEmissPointName"--> -<!-- width="68%"--> -<!-- center--> -<!-- v-dialogDrag--> -<!-- >--> -<!-- <div class="el-dialog-div" style="height: 500px">--> -<!-- <public-detailed-list v-bind="$attrs"></public-detailed-list>--> -<!-- </div>--> -<!-- </el-dialog>--> -<!-- </div>--> - <div style="width:100%;height:1rem;margin-top:-0.1rem;position:absolute;" id="echarts" ref="main"> +<!-- <input list="students">--> +<!-- <datalist id="students">--> +<!-- <option value="Lily">--> +<!-- <option value="Lucy">--> +<!-- <option value="Jim">--> +<!-- <option value="Lily">--> +<!-- </datalist>--> + <el-row type="flex" :gutter="20"> + <el-col :span="14"> +<!-- <el-row>--> +<!-- <el-col :span="12">--> +<!-- <el-row type="flex" justify="space-between">--> +<!-- <el-col class="pickerData">--> +<!-- 寮�濮嬫椂闂�:--> +<!-- <el-date-picker--> +<!-- type="date">--> +<!-- </el-date-picker>--> +<!-- </el-col>--> +<!-- </el-row>--> +<!-- </el-col>--> +<!-- <el-col :span="12" type="flex">--> +<!-- <el-row type="flex" justify="center">--> +<!-- <el-col>--> +<!-- 缁撴潫鏃堕棿:--> +<!-- <el-date-picker--> +<!-- type="date"--> +<!-- >--> +<!-- </el-date-picker>--> +<!-- </el-col>--> +<!-- </el-row>--> +<!-- </el-col>--> +<!-- </el-row>--> + </el-col> + <el-col :span="5"> + 閲囨牱鐐规暟: + <input list="source" id="ipt" class="echatsInput"> + <datalist id="source"> + <option value="0" /> + <option value="25" /> + <option value="50" /> + <option value="75" /> + <option value="100" /> + </datalist> +<!-- <div data-tap-disabled="true">--> +<!-- 閲囨牱鐐规暟:--> +<!-- <select id="source">--> +<!-- <option value="1">0</option>--> +<!-- <option value="2">25</option>--> +<!-- <option value="3">50</option>--> +<!-- <option value="4">75</option>--> +<!-- <option value="5">100</option>--> +<!-- </select>--> +<!-- </div>--> + </el-col> + <el-col class="detailbtn" :span="2" @click="onSubmit">鏌ヨ</el-col> + <el-col :span="3"> + <div class="detailbtn" @click="dialogVisible = true" >鏄庣粏琛�</div> + <el-dialog :visible.sync="dialogVisible" + :append-to-body="true" + :title="this.$attrs.value==='feiqi'?this.$attrs.getWasteGasDetails[0].OnLineMonEmissPointName:this.$attrs.getWasteWaterMonitoringDetails[0].OnLineMonEmissPointName" + width="68%" + center + v-dialogDrag + > + <div class="el-dialog-div" style="height: 500px"> + <public-detailed-list v-bind="$attrs"></public-detailed-list> + </div> + </el-dialog> + </el-col> + </el-row> + </div> + <div style="width:600px;height:200px;" id="echarts" ref="main"> </div> </div> </div> @@ -68,9 +135,33 @@ return { watchData: [], dialogVisible: false, - dataDate: [], + myChar: null, value: '', - options: { + formInline: { + user: '', + region: '' + } + } + }, + methods: { + onSubmit () { + console.log('submit!') + }, + drawChart: function () { + window.onresize = function () { + var h1 = document.documentElement.clientHeight// 鑾峰彇灞忓箷鐨勯珮搴� + if (h1 > 700) { + this.myChart.getDom().style.height = 3 + 'rem' + this.myChart.getDom().style.width = 6 + 'rem' + } else { + this.myChart.getDom().style.height = 3 + 'rem' + this.myChart.getDom().style.width = 6 + 'rem' + } + this.myChart.resize() + } + }, + initOptions: function (dataDate, dataValue1, dataValue2, dataValue3) { + var options = { title: { // text: '鎶樼嚎鍥惧爢鍙�' }, @@ -88,25 +179,19 @@ x: '200px', y: '30px', data: [{ - name: '姘哀鍖栫墿', + name: 'COD', textStyle: { color: '#00d0f9' } }, { - name: '浜屾哀鍖栫~', + name: '姘ㄦ爱', textStyle: { color: '#00d0f9' } }, { - name: '鐑熷皹', - textStyle: { - color: '#00d0f9' - } - }, - { - name: '搴熸皵娴侀噺', + name: '搴熸按娴侀噺', textStyle: { color: '#00d0f9' } @@ -114,12 +199,11 @@ }, grid: { left: '3%', - right: '1%', + right: '6%', bottom: '3%', containLabel: true }, - toolbox: { - }, + toolbox: {}, // 鍥炬爣缂╂斁璁剧疆 dataZoom: [{ type: 'inside', @@ -143,12 +227,13 @@ xAxis: { type: 'category', boundaryGap: false, - data: ['12:00:00', '13:00:00', '14:00:00', '15:00:00', '16:00:00', '17:00:00', '18:00:00'], + data: dataDate, axisLabel: { // x杞村叏閮ㄦ樉绀� rotate: 20, interval: 0, textStyle: { - color: '#fff' + color: '#fff', + fontSize: 10 } }, splitLine: { // 缃戞牸鍨傜洿绾夸负铏氱嚎 @@ -170,9 +255,31 @@ // Y 杞寸殑璁剧疆 yAxis: [{ type: 'value', - // position: 'left', // 澶� Y 杞翠娇鐢� - // name: yname, // 鍚庢湡鍥炬爣Y杞存樉绀哄崟浣� + position: 'left', // 澶� Y 杞翠娇鐢� name: '娴撳害(mg/m鲁)', + axisLabel: { + formatter: '{value}', + textStyle: { + color: '#fff' // 鍧愭爣鐨勫瓧浣撻鑹� + } + }, + axisPointer: { + snap: true // 鑷姩鍚搁檮鏈�杩戠殑鐐� + }, + splitLine: { + show: false // y杞� 缃戞牸绾夸笉鏄剧ず + }, + axisLine: { + lineStyle: { + color: '#ffffff', // 鍧愭爣杞寸殑棰滆壊 + width: 1 + } + } + }, + { + type: 'value', + position: 'right', // 澶� Y 杞翠娇鐢� + name: '娴侀噺(m鲁/h鲁)', axisLabel: { formatter: '{value}', textStyle: { @@ -194,61 +301,68 @@ }], series: [ { - name: '姘哀鍖栫墿', + name: 'COD', type: 'line', stack: '鎬婚噺', - data: [120, 132, 101, 134, 90, 230, 210] + data: dataValue1, + yAxisIndex: 0 }, { - name: '浜屾哀鍖栫~', + name: '姘ㄦ爱', type: 'line', stack: '鎬婚噺', - data: [150, 232, 201, 154, 190, 330, 410] + data: dataValue2, + yAxisIndex: 0 }, { - name: '鐑熷皹', + name: '搴熸按娴侀噺', type: 'line', stack: '鎬婚噺', - data: [320, 332, 301, 334, 390, 330, 320] - }, - { - name: '搴熸皵娴侀噺', - type: 'line', - stack: '鎬婚噺', - data: [820, 932, 901, 934, 1290, 1330, 1320] + data: dataValue3, + yAxisIndex: 1 } ] - }, - formInline: { - user: '', - region: '' } - } - }, - methods: { - onSubmit () { - console.log('submit!') - }, - drawChart: function () { - const myChart = this.$echarts.init(this.$refs.main) - myChart.setOption(this.options) + return options } }, mounted () { this.$nextTick(() => { this.drawChart() - const dataWatch = JSON.parse(JSON.stringify(this.$attrs.getWasteWaterMonitoring)) - // console.log(dataWatch) - for (var i = 0; i < dataWatch.length; i++) { - this.dataDate.push(dataWatch[i].MonTimeStr.substring(10, 17)) + const dataWatch = JSON.parse(JSON.stringify(this.$attrs.getQueryOnlineMonData)).reverse() + console.log(dataWatch) + var dataValue1 = [] + var dataValue2 = [] + var dataValue3 = [] + var dataDate = [] + for (var i = 0; i < 24; i++) { + dataDate.push(dataWatch[i].MonTimeStr.substring(9)) } - // console.log(this.dataDate) + for (var n = 0; n < dataWatch.length; n++) { + if (dataWatch[n].PoltmtrlName === 'COD') { + dataValue1.push(dataWatch[n].MonQty) + } else if (dataWatch[n].PoltmtrlName === '姘ㄦ爱') { + dataValue2.push(dataWatch[n].MonQty) + } else if (dataWatch[n].PoltmtrlName === '搴熸按娴侀噺') { + dataValue3.push(dataWatch[n].MonQty) + } + } + const opitons = this.initOptions(dataDate, dataValue1, dataValue2, dataValue3) + this.myChart = this.$echarts.init(this.$refs.main) + this.myChart.setOption(opitons) }) } } </script> <style scoped lang="less"> +.grid-content{ + font-size: 8px!important; + background-color:#2e4967; + text-align: center; + margin: 0 2px 4px 2px; + border-radius: 2px; +} .Infomation { margin-left: 10px; height: 0.2rem; @@ -256,6 +370,7 @@ .el-tag { height: 25px; + width: 140px; line-height: 25px; margin-right: 10px; font-size: 10px; @@ -270,18 +385,59 @@ height: 1rem; border-top: 1px solid #396d83; //margin: 10px 10px 10px 10px; + .from-search{ + //display: flex; + //justify-content: space-between; + .pickerData{ + display: flex; + justify-content: space-between; + } + /deep/.el-input__inner{ + width: 40px!important; + height: 16px!important; + background-color: #2e4967; + } + .echatsInput{ + color: #00ffff; + background-color: #2e4967; + border: none; + border-radius: 6px; + width: 40px; + } + .detailbtn{ + background-color:#2e4967; + text-align: center; + padding: 0 7px; + line-height: 20px; + border-radius: 4px; + margin-right: 6px; + } + } .el-dialog-div { //height: 50vh!important; overflow: auto; //overflow: hidden; } - #echarts { - margin: 0; - padding: 0; - //height: 3rem; - //border: 1px solid #396d83; - //margin: 10px 10px 10px 10px; - } -} + .from-search { + background-color: red; + .date{ + width: 200px; + height: 30px; + padding: 0; + border: none; + .el-icon-time{ + line-height: 30px; + } + } + } + + #echarts { + margin: 0; + padding: 0; + //height: 3rem; + //border: 1px solid #396d83; + //margin: 10px 10px 10px 10px; + } + } </style> -- Gitblit v1.8.0