赞
踩
参考属性链接:http://echarts.baidu.com/option.html#tooltip.formatter
echarts的tooltip中的一个属性formatter:提示框浮层内容格式器,支持字符串模板和回调函数两种形式。
折线(区域)图、柱状(条形)图、K线图 : {a}(系列名称),{b}(类目值),{c}(数值), {d}(无)
注意: 类目值就是对应的横坐标。
例子:
tooltip: {
trigger: 'axis',
axisPointer: {
type : 'shadow'
},
formatter: '{b} <br /> {a0}: {c0}<br />{a1}: {c1} <br /> {a2}: {c2}' + "%"
},
回调函数格式:(params: Object|Array, ticket: string, callback: (ticket: string, html: string)) => string
例子
tooltip: {
trigger: 'item',
position:'right',
formatter : function(params, ticket, callback) {
if (params.value == undefined || params.value !== params.value) {
params.value = 0;
}
return params.seriesName +" <br />" + params.name + ":" + params.value + "%";
}
},
"tooltip": {
"trigger": "axis",
"axisPointer": {
"type": "shadow",
"textStyle": {
"color": "#fff"
},
"label": {
"precision": 2,
}
},
formatter : function(params, ticket, callback) {
let obj = params.map((item, index) => {
if (item.value == undefined || item.value !== item.value) {
item.value = 0;
}
let percent = ((item.value / params[params.length - 1].value) * 100).toFixed(2)
// 小圆点显示
let dotColor = '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + item.color + '"></span>'
return dotColor + item.seriesName + ":" + item.value + '(' + percent + '%' + ')' + '</br>'
})
return obj.join('') // 去除','
}
},

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。