diff --git a/src/views/govern/device/planData/index.vue b/src/views/govern/device/planData/index.vue index f4bba56..4b769b0 100644 --- a/src/views/govern/device/planData/index.vue +++ b/src/views/govern/device/planData/index.vue @@ -124,7 +124,7 @@ > - + @@ -355,7 +355,6 @@ const filterArray = (array: any) => { const init = (flag: boolean) => { //调用子组件的方法切换的时候tree的节点也变化 let list: any = [] - //颜色数组 const colorList = [ '#DAA521', @@ -434,20 +433,30 @@ const init = (flag: boolean) => { //icon图标替换legend图例 const iconThree = 'path://M512 85.333333c235.637333 0 426.666667 191.029333 426.666667 426.666667S747.637333 938.666667 512 938.666667 85.333333 747.637333 85.333333 512 276.362667 85.333333 512 85.333333z m214.592 318.677334a32 32 0 0 0-45.248 0.064L544.736 541.066667l-81.792-89.109334a32 32 0 0 0-46.613333-0.576l-119.36 123.733334a32 32 0 1 0 46.058666 44.437333l95.754667-99.264 81.418667 88.704a32 32 0 0 0 46.24 0.96l160.213333-160.693333a32 32 0 0 0-0.064-45.248z' - let xAxis: any = [], - timeList: any = [], - unitList: any = [] + // let xAxis: any = [] //x轴数据数组 + // let timeList: any = [] //x轴数据数组 + // y轴单位数组 + let unitList: any = [] + let allUnitArray: any = [] chartsList.map((item: any) => { - timeList.push(item.time) - if (unitList.indexOf(item.unit) == -1) { - unitList.push(item.unit) - } + // timeList.push(item.time) + // if (unitList.indexOf(item.unit) == -1) { + // unitList.push(item.unit) + // } + allUnitArray.push({ name: item.anotherName, unit: item.unit }) }) - xAxis = new Set( - timeList.sort((a: any, b: any) => { - return new Date(a).getTime() - new Date(b).getTime() - }) - ) + // xAxis = new Set( + // timeList.sort((a: any, b: any) => { + // return new Date(a).getTime() - new Date(b).getTime() + // }) + // ) + //去除重复的unit单位数据 + unitList = allUnitArray.reduce((result: any, obj: any) => { + if (!result.some((item: any) => JSON.stringify(item) === JSON.stringify(obj))) { + result.push(obj) + } + return result + }, []) let [min, max] = [0, 0] list.map((item: any, index: any) => { @@ -537,6 +546,7 @@ const init = (flag: boolean) => { `
${ list[i].value[1] == null ? '' : list[i].value[1].toFixed(2) }

` + // ${list[i].unit} } return res } @@ -554,7 +564,7 @@ const init = (flag: boolean) => { yAxis: [ { type: 'value', - name: unitList[0], + name: unitList[0].unit, axisLabel: { color: '#000', fontSize: 14 @@ -592,27 +602,27 @@ const init = (flag: boolean) => { } echartsData.value.options.legend.data = [] + list.map((item: any, index: any) => { item.map((vv: any, indexs: any) => { //处理legend if (chartsList.length != 0) { echartsData.value.options.legend.data.push({ - name: vv.phase + '相' + vv.showName, - icon: iconThree + name: vv.phase + '相' + vv.showName + // icon: iconThree }) } if ( unitList.findIndex((item: any) => { - return item == vv.unit + return item.unit == vv.unit && item.name == vv.showName }) != -1 ) { vv.yAxisIndex = unitList.findIndex((item: any) => { - return item == vv.unit + return item.unit == vv.unit && item.name == vv.showName }) } else { vv.yAxisIndex = 0 } - echartsData.value.options.series.push({ name: vv.phase + '相' + vv.showName, type: 'line', @@ -643,15 +653,15 @@ const init = (flag: boolean) => { }) //处理多y轴 // if (unitList.length != 0 && unitList.length > 1) { - console.log(max, min) - // echartsData.value.options.yAxis[0].yAxisIndex = 0 + // console.log(max, min) + echartsData.value.options.yAxis[0].yAxisIndex = 0 unitList.map((item: any, index: any) => { if (index != unitList.length - 1) { echartsData.value.options.yAxis.push({ type: 'value', position: 'right', offset: index * 80, // y轴位置的偏移量 - name: unitList[index + 1], + name: unitList[index + 1].unit, axisLabel: { color: '#000', fontSize: 14 @@ -678,8 +688,8 @@ const init = (flag: boolean) => { width: 1, type: 'solid' } - } - // yAxisIndex: index + 1 + }, + yAxisIndex: index + 1 }) } })