echart纵坐标标签特别长换行显示

纵坐标

yAxis : [
    {
        type : 'category',
        data : name,
        axisLabel: { //坐标轴刻度标签的相关设置。
        	textStyle: {
				color: '#000',
				fontStyle: 'normal',
				fontFamily: '微软雅黑',
				fontSize: 12,
			},
        	interval : 0,
        	formatter : function(params){
                var newParamsName = "";
                var paramsNameNumber = params.length;
                var provideNumber = 38;
                var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
                if (paramsNameNumber > provideNumber) {
                    for (var p = 0; p < rowNumber; p++) {
                        var tempStr = "";
                        var start = p * provideNumber;
                        var end = start + provideNumber;
                        if (p == rowNumber - 1) {
                            tempStr = params.substring(start, paramsNameNumber);
                        } else {
                            tempStr = params.substring(start, end) + "\n";
                        }
                        newParamsName += tempStr;
                    }

                } else {
                    newParamsName = params;
                }
                return newParamsName
            }
		},
    }
]

效果图:  

 

posted @ 2018-06-15 16:26  小伍w  阅读(3077)  评论(0编辑  收藏  举报