Data Recevice status Monitoring 弹窗图表点击legned,渲染图表的时候,会回到初始定位的地方

This commit is contained in:
任珮宇 2023-11-03 14:42:24 +08:00
parent cb7718b006
commit dae3882b50
2 changed files with 104 additions and 76 deletions

View File

@ -5,22 +5,22 @@
import * as echarts from 'echarts' import * as echarts from 'echarts'
import 'echarts-gl' import 'echarts-gl'
const events = ['click', 'brushEnd'] const events = ['click', 'brushEnd', 'dataZoom']
const zrEvents = ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick', 'contextmenu'] const zrEvents = ['mousemove', 'mousedown', 'mouseup', 'click', 'dblclick', 'contextmenu']
export default { export default {
props: { props: {
option: { option: {
type: Object, type: Object,
default: () => ({}) default: () => ({}),
}, },
opts: { opts: {
type: Object, type: Object,
default: () => {} default: () => {},
}, },
height: { height: {
type: Number, type: Number,
default: null default: null,
} },
}, },
data() { data() {
return {} return {}
@ -31,21 +31,21 @@ export default {
this.initEventListener() this.initEventListener()
}, },
destroyed() { destroyed() {
if(this._chart) { if (this._chart) {
this._chart.dispose() this._chart.dispose()
} }
}, },
methods: { methods: {
initEventListener() { initEventListener() {
events.forEach(eventName => { events.forEach((eventName) => {
this._chart.on(eventName, (params) => { this._chart.on(eventName, (params) => {
this.$emit(eventName, params) this.$emit(eventName, params)
}) })
}) })
const zr = this.getZRender() const zr = this.getZRender()
zrEvents.forEach(eventName => { zrEvents.forEach((eventName) => {
zr.on(eventName, params => { zr.on(eventName, (params) => {
this.$emit(`zr:${eventName}`, params) this.$emit(`zr:${eventName}`, params)
}) })
}) })
@ -62,7 +62,7 @@ export default {
getZRender() { getZRender() {
return this._chart.getZr() return this._chart.getZr()
} },
}, },
watch: { watch: {
option: { option: {
@ -71,14 +71,14 @@ export default {
this._chart.setOption(this.option, this.opts) this._chart.setOption(this.option, this.opts)
} }
}, },
deep: true deep: true,
}, },
height() { height() {
this.$nextTick(() => { this.$nextTick(() => {
this._chart && this._chart.resize() this._chart && this._chart.resize()
}) })
} },
} },
} }
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -1,5 +1,5 @@
<template> <template>
<div style="width: 100%;height: 100%;overflow: auto;padding-top: 76px;"> <div style="width: 100%; height: 100%; overflow: auto; padding-top: 76px">
<!-- 图例 --> <!-- 图例 -->
<div class="legend"> <div class="legend">
<div <div
@ -14,8 +14,14 @@
</div> </div>
</div> </div>
<!-- 图例结束 --> <!-- 图例结束 -->
<custom-chart ref="customChartRef" :option="option" :height="list.length * 295"></custom-chart> <custom-chart
<a-spin style="z-index: 11;position: absolute;top: 45%;left: 48%;" :spinning="spinning" /> ref="customChartRef"
:option="option"
:opts="{ notMerge: true }"
:height="list.length * 295"
@dataZoom="handleZoomChange"
></custom-chart>
<a-spin style="z-index: 11; position: absolute; top: 45%; left: 48%" :spinning="spinning" />
</div> </div>
</template> </template>
@ -32,76 +38,90 @@ const legendList = [
{ {
title: 'SPHDPREL', title: 'SPHDPREL',
color: '#17a840', color: '#17a840',
isShow: true isShow: true,
}, },
{ {
title: 'SPHDF', title: 'SPHDF',
color: '#0cbfb0', color: '#0cbfb0',
isShow: true isShow: true,
}, },
{ {
title: 'QC', title: 'QC',
color: '#1c82eb', color: '#1c82eb',
isShow: true isShow: true,
}, },
{ {
title: 'GASBKPHDPREL', title: 'GASBKPHDPREL',
color: '#d3ad16', color: '#d3ad16',
isShow: true isShow: true,
}, },
{ {
title: 'GASBKPHDF', title: 'GASBKPHDF',
color: '#db6423', color: '#db6423',
isShow: true isShow: true,
}, },
{ {
title: 'SOH/MET', title: 'SOH/MET',
color: '#8852da', color: '#8852da',
isShow: true isShow: true,
} },
] ]
// //
const initialOption = { const initialOption = {
tooltip: { tooltip: {
formatter: params => { formatter: (params) => {
return `${params.marker}${params.name}: ${(params.value[3] / 1000 / 60).toFixed()}min` return `${params.marker}${params.name}: ${(params.value[3] / 1000 / 60).toFixed()}min`
} },
}, },
grid: [], grid: [],
xAxis: [], xAxis: [],
yAxis: [], yAxis: [],
series: [], series: [],
dataZoom: [] dataZoom: [],
} }
export default { export default {
props: { props: {
title: { title: {
type: String type: String,
}, },
spinning: { spinning: {
type: Boolean type: Boolean,
}, },
list: { list: {
type: Array, type: Array,
default: () => [] default: () => [],
}, },
scaleSettings: { scaleSettings: {
type: Object, type: Object,
required: true required: true,
} },
}, },
components: { components: {
CustomChart CustomChart,
}, },
data() { data() {
return { return {
legendList: cloneDeep(legendList), legendList: cloneDeep(legendList),
option: {} option: {},
zoomDataAll: [],
} }
}, },
methods: { methods: {
handleZoomChange(params) {
this.zoomDataAll = this.option.dataZoom.map((item) => {
if (item.id == params.batch[0].dataZoomId) {
return {
id: params.batch[0].dataZoomId,
start: params.batch[0].start,
end: params.batch[0].end,
}
} else {
return item
}
})
},
renderItem(params, api) { renderItem(params, api) {
let categoryIndex = api.value(0) let categoryIndex = api.value(0)
let start = api.coord([api.value(1), categoryIndex]) let start = api.coord([api.value(1), categoryIndex])
@ -113,20 +133,20 @@ export default {
x: start[0], x: start[0],
y: start[1] - height / 2, y: start[1] - height / 2,
width: end[0] - start[0], width: end[0] - start[0],
height: height height: height,
}, },
{ {
x: params.coordSys.x, x: params.coordSys.x,
y: params.coordSys.y, y: params.coordSys.y,
width: params.coordSys.width, width: params.coordSys.width,
height: params.coordSys.height height: params.coordSys.height,
} }
) )
return ( return (
rectShape && { rectShape && {
type: 'rect', type: 'rect',
shape: rectShape, shape: rectShape,
style: api.style() style: api.style(),
} }
) )
}, },
@ -155,13 +175,9 @@ export default {
} }
}, },
initChartOption() { initChartOption(val) {
let now = dayjs(new Date()) let now = dayjs(new Date())
now = now now = now.add(1, 'hour').set('minute', 0).set('second', 0).set('millisecond', 0)
.add(1, 'hour')
.set('minute', 0)
.set('second', 0)
.set('millisecond', 0)
const max = now.valueOf() const max = now.valueOf()
const min = max - this.scaleSettings.cacheTime * 24 * 60 * 60 * 1000 const min = max - this.scaleSettings.cacheTime * 24 * 60 * 60 * 1000
@ -172,7 +188,7 @@ export default {
left: 70, left: 70,
right: 20, right: 20,
top: 70 * index + 225 * index, top: 70 * index + 225 * index,
height: 225 height: 225,
}) })
xAxis.push({ xAxis.push({
@ -182,17 +198,17 @@ export default {
interval: this.scaleSettings.scaleInterval * 60 * 1000, interval: this.scaleSettings.scaleInterval * 60 * 1000,
axisLabel: { axisLabel: {
show: true, show: true,
formatter: val => { formatter: (val) => {
let dateTime = new Date(val) let dateTime = new Date(val)
return dayjs(dateTime).format('HH:mm\nMM/DD') return dayjs(dateTime).format('HH:mm\nMM/DD')
}, },
color: '#ade6ee' color: '#ade6ee',
}, },
splitLine: { splitLine: {
lineStyle: { lineStyle: {
color: '#214751' color: '#214751',
} },
} },
}) })
yAxis.push({ yAxis.push({
@ -202,31 +218,31 @@ export default {
nameTextStyle: { nameTextStyle: {
// //
fontSize: 14, fontSize: 14,
color: '#5b9cba' color: '#5b9cba',
}, },
nameGap: 46, nameGap: 46,
data: typeList, data: typeList,
splitLine: { splitLine: {
show: true, show: true,
lineStyle: { lineStyle: {
color: '#214751' color: '#214751',
} },
}, },
axisLine: { axisLine: {
lineStyle: { lineStyle: {
color: '#214751' color: '#214751',
} },
}, },
axisTick: { axisTick: {
show: false show: false,
}, },
axisLabel: { axisLabel: {
color: '#ade6ee' color: '#ade6ee',
} },
}) })
const data = [] const data = []
item.dataList.forEach(item => { item.dataList.forEach((item) => {
this.convertStatus(item) this.convertStatus(item)
let startTime = new Date(item.beginTime * 1000).getTime() let startTime = new Date(item.beginTime * 1000).getTime()
@ -236,17 +252,17 @@ export default {
const endTime = new Date(item.endTime * 1000).getTime() const endTime = new Date(item.endTime * 1000).getTime()
const duration = endTime - startTime const duration = endTime - startTime
const index = typeList.findIndex(type => item.type == type) const index = typeList.findIndex((type) => item.type == type)
const find = this.legendList.find(legendItem => legendItem.title == item.status) const find = this.legendList.find((legendItem) => legendItem.title == item.status)
if (find.isShow) { if (find.isShow) {
data.push({ data.push({
name: item.status, name: item.status,
value: [index, startTime, endTime, duration], value: [index, startTime, endTime, duration],
itemStyle: { itemStyle: {
normal: { normal: {
color: find.color color: find.color,
} },
} },
}) })
} }
}) })
@ -256,20 +272,22 @@ export default {
renderItem: this.renderItem, renderItem: this.renderItem,
encode: { encode: {
x: [1, 2], x: [1, 2],
y: 0 y: 0,
}, },
data: data, data: data,
xAxisIndex: index, xAxisIndex: index,
yAxisIndex: index yAxisIndex: index,
}) })
if (!val) {
dataZoom.push({ dataZoom.push({
type: 'inside', type: 'inside',
id: index,
xAxisIndex: index, xAxisIndex: index,
start: 100 - (this.scaleSettings.timelineLength / (this.scaleSettings.cacheTime * 24 * 60)) * 100, start: 100 - (this.scaleSettings.timelineLength / (this.scaleSettings.cacheTime * 24 * 60)) * 100,
end: 100, end: 100,
zoomLock: true zoomLock: true,
}) })
}
}) })
this.option = option this.option = option
@ -279,20 +297,30 @@ export default {
handleLegendChange(legend) { handleLegendChange(legend) {
legend.isShow = !legend.isShow legend.isShow = !legend.isShow
this.initChartOption() this.initChartOption()
this.option.dataZoom = this.zoomDataAll.map((item, index) => {
return {
type: 'inside',
id: item.id,
xAxisIndex: index,
start: item.start,
end: item.end,
zoomLock: true,
}
})
}, },
resize() { resize() {
this.$refs.customChartRef.resize() this.$refs.customChartRef.resize()
} },
}, },
watch: { watch: {
list: { list: {
handler() { handler() {
this.initChartOption() this.initChartOption()
}, },
immediate: true immediate: true,
} },
} },
} }
</script> </script>