回调函数
回调函数格式:(params: Object|Array, ticket: string, callback: (ticket: string, html: string)) => string
第一个参数params是 formatter 需要的数据集。格式如下:{
componentType: 'series',
// 系列类型
seriesType: string,
// 系列在传入的 option.series 中的 index
seriesIndex: number,
// 系列名称
seriesName: string,
// 数据名,类目名
name: string,
// 数据在传入的 data 数组中的 index
dataIndex: number,
// 传入的原始数据项
data: Object,
// 传入的数据值
value: number|Array,
// 数据图形的颜色
color: string,
// 饼图的百分比
percent: number,
//
galleryViewPath: ,
//
galleryEditorPath: ,
//
imagePath: ,
//
gl: ,
}
在trigger为'axis'的时候,或者 tooltip 被axisPointer触发的时候,params是多个系列的数据数组。其中每项内容格式同上,并且,
{
componentType: 'series',
// 系列类型
seriesType: string,
// 系列在传入的 option.series 中的 index
seriesIndex: number,
// 系列名称
seriesName: string,
// 数据名,类目名
name: string,
// 数据在传入的 data 数组中的 index
dataIndex: number,
// 传入的原始数据项
data: Object,
// 传入的数据值
value: number|Array,
// 数据图形的颜色
color: string,
}
注:ECharts 2.x 使用数组表示各参数的方式不再支持。
第二个参数ticket是异步回调标识,配合第三个参数callback使用。 第三个参数callback是异步回调,在提示框浮层内容是异步获取的时候,可以通过 callback 传入上述的ticket和html更新提示框浮层内容。
示例:formatter: function (params, ticket, callback) {
$.get('detail?name=' + params.name, function (content) {
callback(ticket, toHTML(content));
});
return 'Loading';
}