打开一个dialog,里面写了个echarts 但是echarts的tooltip一直不显示,是哪块出了问题呢?
<span style="font-weight: normal;color: #0076fe;text-decoration: underline;cursor: pointer;" @click="openHistorySession()">{{currentSession}}</span>
//打开session趋势图
openHistorySession(){
this.dialogVisible = true;
this.$nextTick(() => {
this.initSessionEcharts();
})
},
initSessionEcharts() {
// 初始化时间范围 默认查询最近一天
this.timeRange = [new Date( new Date().getTime() - 60 * 60 * 1000 *24) , new Date()]
this.queryHistorySession()
},
queryHistorySession(){
var param = {
nodeId: this.$route.params.nodeId,
startTime: this.timeRange[0].getTime(),
endTime: this.timeRange[1].getTime()
}
selectHistorySessionInfo(param).then(res =>{
if (res.data.code == 200 ){
if (this.sessionChart) {
this.sessionChart.dispose(); // 避免重复 init 冲突
}
this.sessionChart = echarts.init( this.$refs.historySessionRef);
var sessionOption = {
tooltip: {
trigger: 'axis',
formatter: function (params) {
let result = params[0].name + '<br/>';
params.forEach(function (item) {
result += item.marker + item.seriesName + ': ' + item.value + (item.seriesName === 'session使用率' ? '%' : '个') + '<br/>';
});
return result;
}
},
toolbox: {
feature: {
restore: { show: true },
saveAsImage: { show: true }
}
},
legend: {
data: ['当前session数量', '最大session数量', 'session使用率']
},
grid: {
left: '10%',
right: '10%',
bottom: '15%'
},
xAxis: {
type: 'category',
boundaryGap: false,
data: res.data.data.dateList, // 示例时间点
},
yAxis: [
{
type: 'value',
name: '(个)',
position: 'left',
axisLabel: {
formatter: '{value}'
}
},
{
type: 'value',
name: '(%)',
position: 'right',
axisLabel: {
formatter: '{value}%'
}
}
],
series: [
{
name: '当前session数量',
type: 'line',
data: res.data.data.currentSessionList,
itemStyle: { color: '#5470C6' },
yAxisIndex: 0,
smooth:true//显示为平滑的曲线
},
{
name: '最大session数量',
type: 'line',
data: res.data.data.maxSessionList,
itemStyle: { color: '#91CC75' },
yAxisIndex: 0,
smooth:true//显示为平滑的曲线
},
{
name: 'session使用率',
type: 'line',
data: res.data.data.maxSessionUsedList,
itemStyle: { color: '#FAC858' },
yAxisIndex: 1,
smooth:true//显示为平滑的曲线
}
]
};
this.sessionChart.setOption(sessionOption);
this.$nextTick(() => {
this.sessionChart.resize(); // 必须 resize 一次
});
}
})
},