|
86 | 86 | ], |
87 | 87 | xAxis: { |
88 | 88 | type: 'time', |
89 | | - boundaryGap: false |
| 89 | + boundaryGap: false, |
| 90 | + axisLabel: { |
| 91 | + formatter: function (value) { |
| 92 | + // 确保时间戳正确格式化 |
| 93 | + return echarts.format.formatTime('MM-dd hh:mm', value); |
| 94 | + } |
| 95 | + } |
90 | 96 | }, |
91 | 97 | yAxis: { |
92 | 98 | type: 'value', |
|
178 | 184 | }); |
179 | 185 | }, |
180 | 186 | parseMonitorInfo(monitorInfo) { |
| 187 | + console.log('Monitor Info:', monitorInfo); // 调试日志 |
181 | 188 | let tSeries = []; |
182 | 189 | let tLegendData = []; |
183 | 190 | var lcolors = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc']; |
| 191 | + |
| 192 | + // 检查数据有效性 |
| 193 | + if (!monitorInfo || !monitorInfo.result || monitorInfo.result.length === 0) { |
| 194 | + console.warn('No monitor data available'); |
| 195 | + this.option.title.text = "No Data Available"; |
| 196 | + this.myChart.clear(); |
| 197 | + this.myChart.setOption(this.option); |
| 198 | + return; |
| 199 | + } |
| 200 | + |
184 | 201 | for (let i = 0; i < monitorInfo.result.length; i++) { |
185 | 202 | var lcolor = lcolors[i % lcolors.length]; |
186 | 203 | var rgbaColorMarker = 'rgba(' + parseInt(lcolor.slice(1, 3), 16) + ',' + parseInt(lcolor.slice(3, 5), 16) + ',' + parseInt(lcolor.slice(5, 7), 16) + ',0.5)'; |
187 | 204 | var rgbaColorBar = 'rgba(' + parseInt(lcolor.slice(1, 3), 16) + ',' + parseInt(lcolor.slice(3, 5), 16) + ',' + parseInt(lcolor.slice(5, 7), 16) + ',0.35)'; |
188 | 205 | let loss = 0; |
189 | 206 | let data = []; |
190 | 207 | let datal = []; |
| 208 | + |
| 209 | + // 调试时间戳数据 |
| 210 | + if (i === 0 && monitorInfo.result[i].created_at && monitorInfo.result[i].created_at.length > 0) { |
| 211 | + console.log('First timestamp:', monitorInfo.result[i].created_at[0]); |
| 212 | + console.log('Timestamp type:', typeof monitorInfo.result[i].created_at[0]); |
| 213 | + console.log('Date from timestamp:', new Date(monitorInfo.result[i].created_at[0])); |
| 214 | + } |
| 215 | + |
191 | 216 | for (let j = 0; j < monitorInfo.result[i].created_at.length; j++) { |
192 | 217 | avgDelay = Math.round(monitorInfo.result[i].avg_delay[j]); |
| 218 | + let timestamp = monitorInfo.result[i].created_at[j]; |
| 219 | + |
| 220 | + // 确保时间戳是有效的数字 |
| 221 | + if (typeof timestamp !== 'number' || isNaN(timestamp)) { |
| 222 | + console.warn('Invalid timestamp:', timestamp); |
| 223 | + continue; |
| 224 | + } |
| 225 | + |
193 | 226 | if (avgDelay > 0 && avgDelay < MaxTCPPingValue) { |
194 | | - data.push([monitorInfo.result[i].created_at[j], avgDelay]); |
| 227 | + data.push([timestamp, avgDelay]); |
195 | 228 | } |
196 | 229 | else { |
197 | 230 | loss += 1; |
198 | 231 | datal.push({ |
199 | | - xAxis: monitorInfo.result[i].created_at[j], |
| 232 | + xAxis: timestamp, |
200 | 233 | label: { show: false }, |
201 | 234 | emphasis: { disabled: true }, |
202 | 235 | lineStyle: { |
|
231 | 264 | } |
232 | 265 | }); |
233 | 266 | } |
234 | | - this.option.title.text = monitorInfo.result[0].server_name; |
| 267 | + |
| 268 | + // 设置标题,优先使用第一个有效的服务器名称 |
| 269 | + let titleText = "Network Monitor"; |
| 270 | + if (monitorInfo.result.length > 0 && monitorInfo.result[0].server_name) { |
| 271 | + titleText = monitorInfo.result[0].server_name; |
| 272 | + } |
| 273 | + |
| 274 | + this.option.title.text = titleText; |
235 | 275 | this.option.series = tSeries; |
236 | 276 | this.option.legend.data = tLegendData; |
237 | 277 | const maxLegendsPerRowMobile = localStorage.getItem("maxLegendsPerRowMobile") ? localStorage.getItem("maxLegendsPerRowMobile") : 2; |
|
0 commit comments