xAxis坐标轴指示器的文本标签设置

2018-09-08 11:58 更新

xAxis.axisPointer.label   |   Object

用来控制坐标轴指示器的文本标签。

xAxis.axisPointer.label.show   |   boolean

[ default: false ]

表示是否显示文本标签。如果 tooltip.axisPointer.type 设置为 'cross' 则默认显示标签,否则默认不显示。

xAxis.axisPointer.label.precision   |   number, string

[ default: 'auto' ]

表示文本标签中数值的小数点精度。默认根据当前轴的值自动判断。也可以指定如 2 表示保留两位小数。

xAxis.axisPointer.label.formatter   |   string, Function

[ default: null ]

作为文本标签文字的格式化器。

  • 如果为 function,可以是例如:

    参数:

    {Object} params: 含有:

    • {Object} params.value: 轴当前值,如果 axis.type 为 'category' 时,其值为 axis.data 里的数值;如果 axis.type 为 'time',其值为时间戳。
    • {Array.<Object>} params.seriesData: 一个数组,是当前 axisPointer 最近的点的信息,每项内容如下:
    {
    componentType: 'series',
    // 系列类型
    seriesType: string,
    // 系列在传入的 option.series 中的 index
    seriesIndex: number,
    // 系列名称
    seriesName: string,
    // 数据名,类目名
    name: string,
    // 数据在传入的 data 数组中的 index
    dataIndex: number,
    // 传入的原始数据项
    data: Object,
    // 传入的数据值
    value: number|Array,
    // 数据图形的颜色
    color: string,
    }

    每项内容还包括轴的信息:

    {
    axisDim: 'x', // 'x', 'y', 'angle', 'radius', 'single'
    axisId: 'xxx',
    axisName: 'xxx',
    axisIndex: 3,
    axisValue: 121, // 当前 axisPointer 对应的 value。
    axisValueLabel: '文本'
    }

返回值:

显示的 string。

例如:

formatter: function (params) {
// 假设此轴的 type 为 'time'。
return 'some text' + echarts.format.formatTime(params.value);
}

xAxis.axisPointer.label.margin   |   boolean

[ default: 3 ]

表示 label 距离轴的距离。

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号