From 7098891a4ac92dbe365596883099d63e99b8015c Mon Sep 17 00:00:00 2001 From: zhouwenxuan <1175765986@qq.com> Date: 星期三, 25 十月 2023 09:49:54 +0800 Subject: [PATCH] 图表修改动态id --- src/views/monitorData/gasData/index.vue | 63 ++++++++++++++++++++++++------- 1 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/views/monitorData/gasData/index.vue b/src/views/monitorData/gasData/index.vue index 552db39..fe4ad87 100644 --- a/src/views/monitorData/gasData/index.vue +++ b/src/views/monitorData/gasData/index.vue @@ -38,8 +38,8 @@ </el-button> </el-form> </div> - <div id="gasChart" style="height: 500px;width: auto"></div> - <el-table :data="state.tableData.data" style="width: 100%;margin-top: 20px"> + <div :id="gasChart" style="height: 500px;width: auto"></div> + <el-table :data="state.tableData.data" style="width: 100%;margin-top: 20px" v-loading="loading"> <el-table-column type="index" label="序号" width="80" /> <el-table-column align="center" prop="time" label="采集时间"/> <el-table-column align="center" prop="windSpeed" label="风速"/> @@ -93,6 +93,7 @@ gasList: [] } }); +const gasChart = ref("eChartgasN" + Date .now() + Math .random()) const chooseTime = (val: any) => { let sTime = Date.parse(new Date(val[0])); @@ -112,6 +113,7 @@ } } } +const loading = ref(false); const dataZoomEnd = ref(); const xData = ref([]); const yData = ref([]); @@ -140,14 +142,20 @@ } let resChart = await gasDataApi().getGasLineChart(chartParam); if(resChart.data.code == 100) { - xData.value = resChart.data.data.map((item: any) => { - return item.time; - }) - yData.value = resChart.data.data.map((item: any) => { - return item.gasValue; - }) - dataZoomEnd.value = xData.value.length > 25 ? 30 : 100; - markLines.value = 110; + if (resChart.data.data) { + xData.value = resChart.data.data.map((item: any) => { + return item.time; + }) + yData.value = resChart.data.data.map((item: any) => { + return item.gasValue; + }) + dataZoomEnd.value = xData.value.length > 25 ? 30 : 100; + }else { + xData.value = []; + yData.value = []; + markLines.value = 0; + dataZoomEnd.value = 100; + } initCharts(); }else { ElMessage({ @@ -156,6 +164,7 @@ }); } + loading.value = true; //表格 const pageParam = { pageIndex: state.tableData.listQuery.pageIndex, @@ -172,6 +181,7 @@ state.tableData.total = res.data.total; state.tableData.listQuery.pageIndex = res.data.pageIndex; state.tableData.listQuery.pageSize = res.data.pageSize; + loading.value = false; }else { ElMessage({ type: 'warning', @@ -184,7 +194,10 @@ let res = await gasManageApi().getGas({}); if(res.data.code == 100) { state.tableData.gasList = res.data.data; + console.log("气体",state.tableData.gasList) + //默认选择第一个气体 state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id; + markLines.value = state.tableData.gasList[0].threshold; initInfoData(); }else { ElMessage({ @@ -204,12 +217,18 @@ initInfoData(); }; const search = () => { + state.tableData.listQuery.pageIndex = 1; + const gasObj = state.tableData.gasList.filter(item => { + return item.id == state.tableData.listQuery.searchParams.gas + }); + markLines.value = gasObj[0].threshold; + initInfoData(); - console.log("vla",state.tableData.listQuery.searchParams) } const reset = () => { getNowTime(); state.tableData.listQuery.searchParams.gas = state.tableData.gasList[0].id; + markLines.value = state.tableData.gasList[0].threshold; state.tableData.listQuery.pageIndex = 1; initInfoData(); } @@ -218,7 +237,7 @@ if (myChart.value != null && myChart.value != "" && myChart.value != undefined) { myChart.value.dispose(); } - myChart.value = echarts.init(document.getElementById('gasChart')); + myChart.value = echarts.init(document.getElementById(gasChart.value)); // 指定图表的配置项和数据 const option = { tooltip: { @@ -238,6 +257,20 @@ max: Math.max(markLines.value,...yData.value), min: Math.min(markLines.value,...yData.value) }, + graphic: { + type: 'text', // 类型:文本 + left: 'center', + top: 'middle', + silent: true, // 不响应事件 + invisible: yData.value.length > 0, // 有数据就隐藏 + style: { + fill: '#9d9d9d', + fontWeight: 'bold', + text: '暂无数据', + fontFamily: 'Microsoft YaHei', + fontSize: '25px' + } + }, series: [ { data: yData.value, @@ -249,10 +282,10 @@ position: 'end', // 表现内容展示的位置 color: 'red' // 展示内容颜色 }, - yAxis: markLines.value, + yAxis: markLines.value == 0 ? '':markLines.value , lineStyle: { color: "red", - width: 1, // 0 的时候可以隐藏线 + width: markLines.value == 0 ? 0: 1, // 0 的时候可以隐藏线 type: "solid" // 实线,不写默认虚线 } },],//type: 'average', 平均值, min最小值, max 最大值, median中位数 @@ -278,7 +311,7 @@ // 使用刚指定的配置项和数据显示图表。 myChart.value.setOption(option,true); //自适应宽度 - window.addEventListener('resize', function () { + window.addEventListener('resize',function () { myChart.value.resize(); }) } -- Gitblit v1.9.2