echarts 图例过多分页显示,且定时切换页数
echarts 的配置项:legend配置如下:type: ‘scroll’,
show: true,
type: 'scroll',
orient: 'vertical',
right: '10px',
top: 0,
bottom: 0,
icon: "circle",
data: data,
width: 4,
padding: [0, 0],
itemWidth: 10,
itemHeight: 10,
itemGap: 4,
formatter: function(name) {
var val = 0;
for(var i=0; i<data.length; i++){
if(data[i].name == name){
val = data[i].value;
}
}
return "{title|" + (name.length>4 ? (name.slice(0, 4)+'...') : name) + "} {value|" + (val) + "}"
},
没找到echarts本身获取总页数的地方,自己算了下页数:
var pageNum = Math.ceil(data.length / 4); //4 是每页显示的条数
var myChart = echarts.init(chartsPieDom);
然后:
var curNum = 1;
myChart .on('finished', function () {
clearInterval(objTimer);
objTimer = setInterval(function(){
var index = (curNum % obj.pageNum)*4;
obj.charts.dispatchAction({
type: 'legendScroll',
scrollDataIndex: index
});
curNum++;
}, 2000)
});