This commit is contained in:
guanj
2025-11-18 14:54:52 +08:00
parent 5bed340320
commit ddc8f81196
2 changed files with 54 additions and 60 deletions

View File

@@ -2,7 +2,7 @@
<!-- 指标日趋势图 --> <!-- 指标日趋势图 -->
<el-dialog draggable :title="dialogTitle" v-model="dialogVisible" append-to-body width="70%"> <el-dialog draggable :title="dialogTitle" v-model="dialogVisible" append-to-body width="70%">
<div :style="pageHeight"> <div :style="pageHeight">
<my-echart class="tall" :options="echartList" style="width: 98%" /> <my-echart class="tall" :options="echartList" style="width: 100%" />
</div> </div>
</el-dialog> </el-dialog>
</template> </template>
@@ -13,15 +13,15 @@ import MyEchart from '@/components/echarts/MyEchart.vue'
import { useConfig } from '@/stores/config' import { useConfig } from '@/stores/config'
import { mainHeight } from '@/utils/layout' import { mainHeight } from '@/utils/layout'
import { limitExtentDayData } from '@/api/harmonic-boot/cockpit/cockpit' import { limitExtentDayData } from '@/api/harmonic-boot/cockpit/cockpit'
import { yMethod } from '@/utils/echartMethod'
const prop = defineProps({ const prop = defineProps({
width: { type: [String, Number]}, width: { type: [String, Number] },
height: { type: [String, Number]}, height: { type: [String, Number] },
timeKey: { type: [String, Number]}, timeKey: { type: [String, Number] },
timeValue: { type: Object } timeValue: { type: Object }
}) })
const pageHeight = ref(mainHeight(332)) const pageHeight = mainHeight(0, 2)
const dialogVisible: any = ref(false) const dialogVisible: any = ref(false)
@@ -36,57 +36,45 @@ const echartList = ref()
const init = () => { const init = () => {
echartList.value = { echartList.value = {
title: { title: {
text: dialogText.value, text: dialogText.value
textStyle: {
fontSize: 14,
rich: {
lineName: {
color: '#333',
fontSize: 14
}, },
timeLabel: { legend: {
color: '#333', itemWidth: 20,
fontSize: 14, itemHeight: 20,
padding: [0, 0, 0, 10] itemStyle: { opacity: 0 }, //去圆点
right: 70
}, },
name: { tooltip: {
color: '#333', trigger: 'axis',
fontSize: 14, formatter: (params: any) => {
padding: [0, 0, 0, 10] if (!params || params.length === 0) return ''
}
} // 使用第一个项目的轴标签作为时间标题
let tooltipText = params[0].axisValueLabel + '<br/>'
// 遍历所有项目并累加到tooltipText中
params.forEach((item: any) => {
// 将数值格式化为保留两位小数
const formattedValue = Math.round(item.value[1] * 100) / 100
tooltipText += `${item.marker} ${item.seriesName}: ${formattedValue}<br/>`
})
return tooltipText
} }
}, },
xAxis: { xAxis: {
type: 'category', type: 'time',
data: [] axisLabel: {
}, formatter: {
yAxis: { day: '{MM}-{dd}',
type: 'value', month: '{MM}',
name: '数值' year: '{yyyy}'
},
grid: {
left: '1%',
right: '45px',
bottom: '40px',
top: '15%',
containLabel: true
},
dataZoom: [
{
type: 'inside',
height: 13,
start: 0,
bottom: '20px',
end: 100
},
{
start: 0,
height: 13,
bottom: '20px',
end: 100
} }
], }
},
yAxis: {},
options: { options: {
series: [] series: []
} }
@@ -98,6 +86,7 @@ const initData = async (row: any) => {
if (res.data && res.data.length > 0) { if (res.data && res.data.length > 0) {
// 重新初始化图表 // 重新初始化图表
init() init()
let [min, max] = yMethod(res.data.map((item: any) => item.value.split(',')).flat())
// 从第一条数据中提取时间作为x轴数据 // 从第一条数据中提取时间作为x轴数据
const firstItem = res.data[0] const firstItem = res.data[0]
@@ -112,12 +101,17 @@ const initData = async (row: any) => {
// 处理每条相位数据 // 处理每条相位数据
const seriesData = res.data.map((item: any) => { const seriesData = res.data.map((item: any) => {
const values = item.value.split(',').map((v: string) => parseFloat(v) || 0) const values = xAxisData.map((time: string, index: number) => {
// 将传入的日期与时间拼接成完整的时间字符串
const fullTime = `${row.time} ${time}`
const value = parseFloat(item.value.split(',')[index]) || 0
return [fullTime, value]
})
return { return {
name: `${item.phasic}`, name: `${item.phasic}`,
type: 'line', type: 'line',
showSymbol: true, showSymbol: false,
smooth: true, smooth: true,
data: values, data: values,
itemStyle: { itemStyle: {
@@ -128,20 +122,20 @@ const initData = async (row: any) => {
} }
} }
}) })
echartList.value.yAxis.max = max
echartList.value.yAxis.min = min
// 更新图表配置 // 更新图表配置
echartList.value.xAxis.data = xAxisData
echartList.value.options.series = seriesData echartList.value.options.series = seriesData
// 注意:使用时间轴时不需要设置 xAxis.data
} }
}) })
} }
onMounted(() => {}) onMounted(() => {})
const open = async (row: any) => { const open = async (row: any) => {
dialogVisible.value = true dialogVisible.value = true
dialogTitle.value = row.name + '日趋势图' dialogTitle.value = row.name + '日趋势图'
dialogText.value = `{lineName|${row.lineName}}{timeLabel|${row.time}}{name|${row.name}日趋势图}` dialogText.value = `监测点名称:${row.lineName}_越限时间:${row.time}_指标名称:${row.name}`
nextTick(() => { nextTick(() => {
initData(row) initData(row)
}) })

View File

@@ -119,7 +119,7 @@ const tableStore: any = new TableStore({
} }
}, },
{ {
title: '发生日期', title: '越限时间',
field: 'time', field: 'time',
minWidth: '60', minWidth: '60',
render: 'customTemplate', render: 'customTemplate',