Commit a516d3ff2b95feb854cca1441a767cc9d2801cb0

Authored by ww
1 parent 289e59e2

perf: 优化折线图取值区间

@@ -43,6 +43,12 @@ const handleHistoryData = (message: SubscriptionData, attr: string) => { @@ -43,6 +43,12 @@ const handleHistoryData = (message: SubscriptionData, attr: string) => {
43 } as EChartsOption) 43 } as EChartsOption)
44 } 44 }
45 45
  46 +function sliceData(data: any[], maxLength = 20) {
  47 + if (data.length > maxLength)
  48 + return data.slice(1)
  49 + return data
  50 +}
  51 +
46 const handlerTimeSeriesData = (message: SubscriptionData, attr: string) => { 52 const handlerTimeSeriesData = (message: SubscriptionData, attr: string) => {
47 const { ts, latestValue } = useLatestMessageValue(message, attr) 53 const { ts, latestValue } = useLatestMessageValue(message, attr)
48 const option = unref(chartInstance)?.getOption() as EChartsOption 54 const option = unref(chartInstance)?.getOption() as EChartsOption
@@ -51,8 +57,8 @@ const handlerTimeSeriesData = (message: SubscriptionData, attr: string) => { @@ -51,8 +57,8 @@ const handlerTimeSeriesData = (message: SubscriptionData, attr: string) => {
51 xAxisData.push(formatToDateTime(ts)) 57 xAxisData.push(formatToDateTime(ts))
52 seriesData.push(latestValue) 58 seriesData.push(latestValue)
53 unref(chartInstance)?.setOption({ 59 unref(chartInstance)?.setOption({
54 - xAxis: { data: xAxisData },  
55 - series: { data: seriesData }, 60 + xAxis: { data: sliceData(xAxisData) },
  61 + series: { data: sliceData(seriesData) },
56 } as EChartsOption) 62 } as EChartsOption)
57 } 63 }
58 64