1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
| <template> <section> <!--工具条--> <el-col :span="24" class="toolbar" style="padding-bottom: 0px;"> <el-form :inline="true" :model="filters">
<el-col :span="24">
<el-form-item label="房间"> <el-select v-model="filters.roomNo" placeholder="房间"> <el-option :value="type.no" :label="type.name" v-for="type in roomList" ></el-option> </el-select> </el-form-item>
<el-form-item label="设备类型"> <el-select v-model="filters.deviceTp" placeholder="设备类型"> <el-option :value="type.value" :label="type.label" v-for="type in deviceTpList" ></el-option> </el-select> </el-form-item>
<el-form-item label="数据类型"> <el-select v-model="filters.dataTp" @change="dataTpChange" placeholder="数据类型"> <el-option v-for="item in dataTpList" :key="item.value" :label="item.label" :value="item.value"> </el-option> </el-select>
</el-form-item> </el-col>
<el-col :span="24" align="center"> <el-form-item> <el-button type="primary" v-on:click="drawLineChart">查询</el-button> </el-form-item> </el-col> </el-form> </el-col>
<!-- 统计图 --> <el-col :span="24" class="toolbar" style="padding-bottom: 0px;"> <v-chart :options="myEchartsOption" :init-options="initOptions" auto-resize style="width:100%; height:400px;" /> </el-col>
</section> </template>
<script> import util from '../../common/js/util'; import {getStatList} from "../../api/stat"; import {getDeviceTpList} from "../../api/config"; import {getRoomList} from "../../api/room"; //导入v-charts import Echarts from 'vue-echarts' import 'echarts/lib/chart/line'
export default { data() { return { filters: { roomNo:'',deviceTp:'',dataTp:'0' }, dataList: [], total: 0, page: 1, listLoading: false, currentSelect: {},//列表选中列 roomList: [], deviceTpList: [], dataTpList:[{value:'0',label:"PM2.5"},{value:"1",label:"温度"},{value:"2",label:"湿度"}, {value:"3",label:"二氧化碳浓度"},{value:"4",label:"TVOC"}], //echart myEChart:{}, //标题 title:'PM2.5历史数据折线图', //echarts配置 myEchartsOption:{}, //配置值,用于封装数据库查询出的真实数据 myEchartsOptionValue:{}, symbolSize:20, initOptions: { renderer: 'canvas' },
} }, methods: {
//获得echarts配置值,查询数据库并封装返回 drawLineChart() {
// 查询条件 let para = { roomNo:this.filters.roomNo, deviceTp:this.filters.deviceTp, dataTp:this.filters.dataTp, }; // 查询数据库 getStatList(para).then((res) => { if(res.data.code!=200){ return; }
let datas = res.data.dataList;
/**let optionValue = { * xDatas:xDatas, //横坐标数据数组 * dataValues:dayValues, //数据集合 * }; * */ //横坐标数据数组 let xDatas = []; //数据集合 let dataValues = [];
if(datas && datas.length!==0){ //遍历封装 for (let i =0;i< datas.length;i++) {
//x轴数据 let xValue = util.formatDate.format(new Date(datas[i].smplTm), 'yyyy-MM-dd hh:mm:ss'); xDatas.push(xValue); //y轴数据 let yValue = datas[i].val; dataValues.push([xValue,yValue]);
}
}
//封装数据 this.myEchartsOptionValue={ xDatas:xDatas, dataValues:dataValues };
//根据数据准备Echarts配置项 this.getEchartsOption(this.myEchartsOptionValue);
});
},
// 获得Echarts配置项 /**let optionValue = { * xDatas:dayTradeDt, //横坐标数据数组 * dataValues:dayValues, //数据集合 * }; * */ getEchartsOption:function(optionValue){
this.myEchartsOption = { title: { text: this.title }, tooltip: { triggerOn: 'none', formatter: function (params) { return 'X: ' + params.data[0].toFixed(2) + '<br>Y: ' + params.data[1].toFixed(2); } }, grid: { }, xAxis: { min:null, max:null, type: 'category', boundaryGap: false, //横坐标显示数据 data: optionValue.xDatas, //切割份数 splitNumber:5, }, yAxis: { min:-100, max:500, type: 'value', axisLine:{onZero:false} }, dataZoom: [ { type: 'slider', xAxisIndex: 0, filterMode: 'empty' }, { type: 'slider', yAxisIndex: 0, filterMode: 'empty' }, { type: 'inside', xAxisIndex: 0, filterMode: 'empty' }, { type: 'inside', yAxisIndex: 0, filterMode: 'empty' } ], series: [ { id: 'a', type: 'line', smooth: true, symbolSize: 20, // 数据 data: optionValue.dataValues, } ] };
},
//房间下拉初始化 initRoomList: function () {
let para = {}; //查询 getRoomList(para).then((res)=>{ //条件查询下拉 for (let resKey of res.data.dataList) { this.roomList.push(resKey); } }) },
//数据类型下拉初始化 initDeviceTpList: function () {
let para = {key:"DEVICE_TP"}; //查询常量 getDeviceTpList(para).then((res)=>{ //条件查询下拉 for (let resKey of res.data.dataList) { this.deviceTpList.push(resKey); } }) },
}, created() { //初始化下拉数据 this.initRoomList(); this.initDeviceTpList(); //初始化echarts数据 this.drawLineChart(); } };
</script>
<style scoped>
</style>
|