echarts中tooltip方法和formatter结合时的处理
export const tooltip = () => {
let tooltip = {
trigger: 'axis',
textStyle: {
color: 'black',
},
borderWidth: '1',
borderColor: '#eee',
backgroundColor: 'rgba(255,255,255,1)'
}
return tooltip
}
export const formatterFun = (data, str) => {
var htmlStr = '';
var valMap = {};
for (var i = 0; i < data.length; i++) {
var param = data[i];
var xName = param.name;
var seriesName = param.seriesName;
var value = param.value;
var color = param.color;
if (value == '-') {
continue;
}
if (valMap[seriesName] == value) {
continue;
}
htmlStr += xName + '<br/>';
htmlStr += '<div>';
htmlStr += '<span style="margin-right:5px;display:inline-block;width:10px;height:10px;border-radius:5px;background-color:' + color + ';"></span>';
if (str == 'lc') {
htmlStr += seriesName + ':' + value + '%';
} else {
htmlStr += seriesName + ':' + value;
}
htmlStr += '</div>';
valMap[seriesName] = value;
}
return htmlStr;
}
this.charts.setOption({
tooltip:{
...tooltip(),
formatter: function(data){
return formatterFun(data)
},
}
})