ECharts 柱状图上显示数据,并自定义图标
先看效果
1.柱状图上显示数据,使用的是series[0].label.formatter
series: [{
name:'近一周每日',
type: 'bar',
barGap: '0',
label: {
normal: {
show: true,
formatter: '{c}%',
position: "top",
textStyle: {
color: "#fff",
fontSize: 14
}
}
}
}
2.柱形图上添加自定义icon,也是在series里面,在lable的同级添加如下代码
markPoint: {
formatter: function(params){
return '<img src="'
+ params.data.symbol.replace('image://', '')
+ '"/>';
},
symbolSize:'15',
data: [
{coord: [0,10],symbolOffset:[20,-20],symbol:'image://../../../static/img/top.png'},
{coord: [1,10],symbolOffset:[20,-20],symbol:'image://../../../static/img/bottom.png'},
{coord: [2,20],symbolOffset:[20,-20],symbol:'image://../../../static/img/top.png'},
{coord: [3,20],symbolOffset:[20,-20],symbol:'image://../../../static/img/top.png'},
{coord: [4,20],symbolOffset:[20,-20],symbol:'image://../../../static/img/bottom.png'},
{coord: [5,20],symbolOffset:[20,-20],symbol:'image://../../../static/img/top.png'},
{coord: [6,20],symbolOffset:[20,-20],symbol:'image://../../../static/img/bottom.png'},
],
label:{
show:true,
position:'middle'
}
}
coord:[0,10],一个参数是我们想要添加icon柱形图的index,第二个是柱形图的value,即我们显示在柱形图上的数据
symbolOffset:使我们icon在柱状图上的位置,分别代表x,y轴的偏移量
symbol:是我们添加icon的路径,格式是image://+图片路径