//评价标签情况柱状图
var tabChartContainer = function () {
$('#tabChart').css('height','320px');
};
tabChartContainer();
var tabChart = echarts.init(document.getElementById('tabChart'));
var options = {
tooltip : {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
},
formatter: function(datas)
{
var res = datas[0].name + '<br/>', val;
for(var i = 0, length = datas.length; i < length; i++) {
val = (datas[i].value*100) + '%';
res += datas[i].seriesName + ':' + val + '<br/>';
}
return res;
}
},
legend: {
data:['好评率']
},
grid: {
left: '3%',
right: '4%',
containLabel: true
},
xAxis : [
{
type : 'category',
data : ['住户1','住户2','住户3','住户4','住户5','住户6','住户7','住户8','住户9']
}
],
yAxis : [
{
type : 'value',
axisLabel: {
show: true,
interval: 'auto',
formatter: function(value){
if(value==0)
{
return value;
}else {
return value*100+'%';
}
}
}
}
],
dataZoom : [{
show : true,
realtime : false,
start : 0,
end :50
}],
series : [
{
name:'好评率',
type:'bar',
barWidth:'35',
data:[0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9],
itemStyle:{
normal:{
color:'#ff7000'
}
},
label:{
normal:{
show:true,
position:'insideTop'
},
}
}
]
};
tabChart.setOption(options);
echarts的tooltip组件中的一个formatter方法实现,formatter支持字符串和回调函数两种配置方式(本文描述回调函数的实现方式)。
formatter: function(datas)
{
var res = datas[0].name + '<br/>', val;
for(var i = 0, length = datas.length; i < length; i++) {
val = (datas[i].value*100) + '%';
res += datas[i].seriesName + ':' + val + '<br/>';
}
return res;
}