Commit d28b93aef27f47d557701ae09c556e79e0fd4bdb

Authored by ww
1 parent 69642e56

fix: 优化折现图实时推送

... ... @@ -25,8 +25,6 @@ export const getDefaultOption = (): EChartsOption => {
25 25 },
26 26 xAxis: { type: 'category' },
27 27 yAxis: {},
28   - // Declare several bar series, each will be mapped
29   - // to a column of dataset.source by default.
30 28 series: [
31 29 { type: 'line' },
32 30 ],
... ...
1 1 <script lang="ts" setup>
2 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 4 import { init } from 'echarts'
5 5 import { getDefaultOption } from './index.config'
6 6 import type { CreateComponentType, RenderComponentExposeType } from '@/core/Library/types'
... ... @@ -56,16 +56,11 @@ const handlerTimeSeriesData = (commandSource: CommandSource, message: Subscripti
56 56 const { deviceName } = deviceInfo || {}
57 57 const { ts, latestValue } = useLatestMessageValue(message, attr)
58 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 65 unref(chartInstance)?.setOption({
71 66 title: {
... ... @@ -73,15 +68,8 @@ const handlerTimeSeriesData = (commandSource: CommandSource, message: Subscripti
73 68 },
74 69 dataset: {
75 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 73 } as EChartsOption)
86 74 }
87 75
... ...