echarts自定义tooltip

tooltip配置

tooltip: {
        show: true,
        trigger: 'axis',
        formatter: params => {
            let result = `<div>${params[0].axisValue}</div>`
            params.forEach(item => {
                if (item.seriesType === 'line') {
                    result += `<div style="display: flex; width: 100%; margin-top: 4px; justify-content: space-between; align-items: center;">
                                        <div>${item.marker}${item.seriesName}</div>
                                        <div style="margin-left: 12px; color: #666; font-weight: 900;">${(item.value * 100).toFixed(2) + '%'}</div>
                                    </div>`
                } else {
                    result += `<div style="display: flex; width: 100%; margin-top: 4px; justify-content: space-between; align-items: center;">
                                        <div>${item.marker}${item.seriesName}</div>
                                        <div style="margin-left: 12px; color: #666; font-weight: 900;">${item.value}</div>
                                    </div>`
                }
            })
            return result
        }
},

 

posted @ 2024-11-14 17:46  hong_li  阅读(11)  评论(0编辑  收藏  举报