Commit d28b93aef27f47d557701ae09c556e79e0fd4bdb

Authored by ww
1 parent 69642e56

fix: 优化折现图实时推送

@@ -25,8 +25,6 @@ export const getDefaultOption = (): EChartsOption => { @@ -25,8 +25,6 @@ export const getDefaultOption = (): EChartsOption => {
25 }, 25 },
26 xAxis: { type: 'category' }, 26 xAxis: { type: 'category' },
27 yAxis: {}, 27 yAxis: {},
28 - // Declare several bar series, each will be mapped  
29 - // to a column of dataset.source by default.  
30 series: [ 28 series: [
31 { type: 'line' }, 29 { type: 'line' },
32 ], 30 ],
1 <script lang="ts" setup> 1 <script lang="ts" setup>
2 import { computed, onMounted, onUnmounted, ref, unref } from 'vue' 2 import { computed, onMounted, onUnmounted, ref, unref } from 'vue'
3 -import type { DatasetComponentOption, ECharts, EChartsOption, SeriesOption, XAXisComponentOption } from 'echarts' 3 +import type { DatasetComponentOption, ECharts, EChartsOption } from 'echarts'
4 import { init } from 'echarts' 4 import { init } from 'echarts'
5 import { getDefaultOption } from './index.config' 5 import { getDefaultOption } from './index.config'
6 import type { CreateComponentType, RenderComponentExposeType } from '@/core/Library/types' 6 import type { CreateComponentType, RenderComponentExposeType } from '@/core/Library/types'
@@ -56,16 +56,11 @@ const handlerTimeSeriesData = (commandSource: CommandSource, message: Subscripti @@ -56,16 +56,11 @@ const handlerTimeSeriesData = (commandSource: CommandSource, message: Subscripti
56 const { deviceName } = deviceInfo || {} 56 const { deviceName } = deviceInfo || {}
57 const { ts, latestValue } = useLatestMessageValue(message, attr) 57 const { ts, latestValue } = useLatestMessageValue(message, attr)
58 const option = unref(chartInstance)?.getOption() as EChartsOption 58 const option = unref(chartInstance)?.getOption() as EChartsOption
59 - const oldDataset = (option.dataset as DatasetComponentOption[])?.[0].source  
60 - // const xAxisData = ((option.xAxis as XAXisComponentOption[])?.[0] as { data: string[] }).data  
61 - // const seriesData = ((option.series as SeriesOption[])?.[0].data) as SeriesOption[]  
62 - // console.log(option)  
63 - // oldDataset.  
64 - // xAxisData.push(formatToDateTime(ts))  
65 - // seriesData.push({  
66 - // name: attrInfo.name,  
67 - // data: [],  
68 - // }) 59 + const oldDataset = (option.dataset as DatasetComponentOption[])?.[0].source as Recordable[]
  60 + oldDataset.push({
  61 + ts: formatToDateTime(ts),
  62 + [attr]: latestValue,
  63 + })
69 64
70 unref(chartInstance)?.setOption({ 65 unref(chartInstance)?.setOption({
71 title: { 66 title: {
@@ -73,15 +68,8 @@ const handlerTimeSeriesData = (commandSource: CommandSource, message: Subscripti @@ -73,15 +68,8 @@ const handlerTimeSeriesData = (commandSource: CommandSource, message: Subscripti
73 }, 68 },
74 dataset: { 69 dataset: {
75 dimensions: ['ts', attr], 70 dimensions: ['ts', attr],
76 - source: [  
77 - { ts, [attr]: latestValue },  
78 - ], 71 + source: sliceData(oldDataset),
79 }, 72 },
80 - // legend: {  
81 - // data: [attrInfo.name],  
82 - // },  
83 - // xAxis: { data: sliceData(xAxisData) },  
84 - // series: { data: sliceData(seriesData) },  
85 } as EChartsOption) 73 } as EChartsOption)
86 } 74 }
87 75