ECharts axisPointer cross 格式化 X 轴与 Y 轴的 label

ECharts About 667 words

十字准星指示器

typecross时,labelformatter的参数对象中axisDimension表示是X轴还是Y轴。

示例

例子中的xAxis类型是time,所以使用了时间格式化工具类对X轴的label进行格式化,对于Y轴则使用保留两位小数的方法。

const option = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: "cross",
            label: {
                formatter: (params) => {
                    if (params.axisDimension === 'x') {
                        return echarts.time.format(params.value, '{yyyy}-{MM}', false);
                    } else {
                        return params.value.toFixed(2);
                    }
                }
            },
        }
    },
}

文档

https://echarts.apache.org/zh/option.html#tooltip.formatter

Views: 8 · Posted: 2026-03-24

———         Thanks for Reading         ———

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Prev Post
Today In History
Browsing Refresh