Echarts参数属性学习:formatter字符串&返回函数的实战案例

formatter内容格式器,支持字符串模板和回调函数两种形式。
回调函数格式:(params: Object|Array, ticket: string, callback: (ticket: string, html: string)) => string

{
    componentType: 'series',
    // 系列类型
    seriesType: string,
    // 系列在传入的 option.series 中的 index
    seriesIndex: number,
    // 系列名称
    seriesName: string,
    // 数据名,类目名
    name: string,
    // 数据在传入的 data 数组中的 index
    dataIndex: number,
    // 传入的原始数据项
    data: Object,
    // 传入的数据值。在多数系列下它和 data 相同。在一些系列下是 data 中的分量(如 map、radar 中)
    value: number|Array|Object,
    // 坐标轴 encode 映射信息,
    // key 为坐标轴(如 'x' 'y' 'radius' 'angle' 等)
    // value 必然为数组,不会为 null/undefied,表示 dimension index 。
    // 其内容如:
    // {
    //     x: [2] // dimension index 为 2 的数据映射到 x 轴
    //     y: [0] // dimension index 为 0 的数据映射到 y 轴
    // }
    encode: Object,
    // 维度名列表
    dimensionNames: Array<String>,
    // 数据的维度 index,如 0 或 1 或 2 ...
    // 仅在雷达图中使用。
    dimensionIndex: number,
    // 数据图形的颜色
    color: string,

    // 饼图的百分比
    percent: number,

}

示例A:

        formatter: function (obj) {
            var value = obj.value;
            return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">'
                + obj.seriesName + ' ' + value[0] + '日:'
                + value[7]
                + '</div>'
                + schema[1].text + ':' + value[1] + '<br>'
                + schema[2].text + ':' + value[2] + '<br>'
                + schema[3].text + ':' + value[3] + '<br>'
                + schema[4].text + ':' + value[4] + '<br>'
                + schema[5].text + ':' + value[5] + '<br>'
                + schema[6].text + ':' + value[6] + '<br>';
        }
发布了105 篇原创文章 · 获赞 16 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_41290949/article/details/104220440