好的我成功了,让我们继续刚才的问题,现在我的代码变成了这样 showQueueData(){ let dataMap = {}; this.responseData.forEach(item => { if (!dataMap[item.name]) { dataMap[item.name] = { name: item.name, type: 'line', data: [], }; } dataMap[item.name].data.push({ value: [item.monitorDate, item.enqueueCountDiff], queueSize: item.queueSize, enqueueCount: item.enqueueCount, dequeueCount: item.dequeueCount, enqueueCountDiff: item.enqueueCountDiff, dequeueCountDiff: item.dequeueCountDiff, consumerCount: item.consumerCount, producerCount: item.producerCount, symbol: 'circle', // 配置标记样式 symbolSize: 4, // 配置标记大小 }); }); let seriesData = Object.values(dataMap); let myChartOptions = { tooltip: { trigger: 'item', axisPointer: { type: 'line', lineStyle: { color: '#999' } }, formatter: params => { let data = params.data; return `${data.name}<br/> queueSize: ${data.queueSize}<br/> enqueueCount: ${data.enqueueCount}<br/> enqueueCountDiff: ${data.enqueueCountDiff}<br/> dequeueCount: ${data.dequeueCount}<br/> dequeueCountDiff: ${data.dequeueCountDiff}<br/> consumerCount: ${data.consumerCount}<br/> producerCount: ${data.producerCount}` }, }, xAxis: { type: 'time', }, yAxis: { type: 'value', }, series: seriesData, }; let myChart = this.$echarts.init(document.getElementById("myChart")); myChart.setOption(myChartOptions) }, 我的问题是我的悬浮窗上面第一行为undefined 而它本应该展示这个数据点的name属性,我代码哪里错了吗 我数据里的name属性格式为:类似"QUEUE_TSCOMPARE||172.28.179.188"这样
时间: 2024-02-10 10:10:07 浏览: 94
datamap插件
5星 · 资源好评率100%
你的代码中出现了 `undefined`,可能是因为 `data.name` 为空或未定义。你可以在 `formatter` 函数的第一行添加如下代码,判断 `data.name` 是否存在,如果不存在则返回空字符串。修改后的代码如下:
```
formatter: params => {
let data = params.data;
if (!data.name) { // 判断name是否存在
return '';
}
return `${data.name}<br/>
queueSize: ${data.queueSize}<br/>
enqueueCount: ${data.enqueueCount}<br/>
enqueueCountDiff: ${data.enqueueCountDiff}<br/>
dequeueCount: ${data.dequeueCount}<br/>
dequeueCountDiff: ${data.dequeueCountDiff}<br/>
consumerCount: ${data.consumerCount}<br/>
producerCount: ${data.producerCount}`
},
```
阅读全文