关于echarts中formatter 的使用,想请教一个问题。
起因是我想在使用formatter调用自定义的数据。比如下面这个数据源
data : [ {name: "严重", value: 20, count: 455}, {name: "正常", value: 40, count: 784} ]
formatter在 tooltip中可以直接定义函数,能直接取到对象数据
tooltip : { trigger: 'item', formatter: function(data){ console.log(data); return data[1]+":"+data[5].count; } }
但是在series内的label中使用formatter,就不知道怎么取刚刚定义的count了
label:{ show:true, position:'top', textStyle:{ fontSize:12, color:"green" }, formatter:function(a,b,c){ /* 这里要怎么取刚刚的count呢 */ //return c+"%"; } }
可以放在data中
formatter:function (params,ticket,callback) {
var res = '所选地区:' + params.name+'<br/>';
res+='总信息数:'+params.value+'<br/>';
res+='平均信息数:'+params.data.count+'<br/>';
res+='每小时信息数:'+params.data.count+'<br/>';
res+='排名:'+params.data.rank+'<br/>';
setTimeout(function (){callback(ticket, res);}, 1000);
return 'loading';
}
series : [{
name: '数量',
type: 'map',
mapType: '广东',
itemStyle:{
normal:{label:{show:false}},
emphasis:{label:{show:true}}
},
mapLocation: {
x: '10%'
},
roam: true,
data:[
{name: '清远市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '韶关市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '湛江市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '梅州市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '河源市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '肇庆市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '惠州市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '茂名市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '江门市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '阳江市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '云浮市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '广州市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '汕尾市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '揭阳市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '珠海市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '佛山市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '潮州市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '汕头市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '深圳市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '东莞市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)},
{name: '中山市',value: Math.round(Math.random()*1000),rank:Math.round(Math.random()*100),count:Math.round(Math.random()*10000)}
]
}
]