在第一个series里,设置了label为emphasis时显示文本的格式不生效,但是如果改emphasis为normal时,formatter才生效。但是echarts3里的文档写着normal和emphasis的用法是一样的啊
配置项如下
option = {
title: {
text: '折线图堆叠',
top: 0
},
tooltip: {
trigger: 'axis',
formatter: function (params) {
var content = params[0].name;
if (params[0].name == 0) {
content = '';
}
else {
content += '<br>'
}
content += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + params[0].color + '"></span>';
content += params[0].seriesName + ' : ';
content += params[0].value.toFixed(2) + '<br>';
content += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:' + params[1].color + '"></span>';
content += params[1].seriesName + ' : ';
content += (params[1].value * 100).toFixed(2) + '%'
return content;
}
},
legend: {
data:['avgranking','关键词覆盖度']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
name: '小时',
nameGap: 20,
nameTextStyle: {
color: '#696969'
},
type: 'category',
boundaryGap: true,
axisTick: {
inside: true
},
axisLine: {
lineStyle: {
color: '#b7b9bd'
}
},
axisLabel: {
textStyle: {
color: '#696969'
}
},
data: ['0','1','2','3','4','5','6','7','8','9','10','11']
},
yAxis: [
{
type: 'value',
axisLine: {
show: false
},
axisTick: {
show: false
},
axisLabel: {
textStyle: {
color: '#696969'
}
},
max: 1.8,
splitLine: {
show: false
}
},
{
type: 'value',
axisLine: {
show: false
},
axisTick: {
show: false
},
splitLine: {
show: false
},
max: 0.8,
axisLabel: {
formatter: function (value, index) {
if (index === 0) {
return 0;
}
return (value * 100).toFixed(2) + '%';
},
textStyle: {
color: '#696969'
}
}
}
],
series: [
{
name:'avgranking',
type:'line',
symbol: 'circle',
symbolSize: 7,
label: {
emphasis: {
show: true,
formatter: (item) => {
return item.value.toFixed(2);
}
}
},
data:[1.6972807491446065, 1.687272396212673, 1.689159494598059, 1.6954452118723167, 1.6801678703884442, 1.6630155910795343, 1.6596720671481553, 1.649119392818916, 1.6637633996937213, 1.6784004505773022, 1.6723142803947124, 1.6881126358937801]
},
{
name:'关键词覆盖度',
type:'line',
yAxisIndex: 1,
symbol: 'circle',
symbolSize: 7,
data:[0.7997987927565392,
0.7686116700201208,
0.772635814889336,
0.7585513078470825,
0.7334004024144869,
0.7223340040241448,
0.7223340040241448,
0.7354124748490946,
0.7414486921529175,
0.7605633802816901,
0.7716297786720322,
0.7907444668008048
]
}
]
};