换行.png
//格式化图表横坐标文字 let textFormatter = function(e) { let arr = e.split(",");/// 将字符串转数组 let str = arr[0] + "\n" + arr[1]; return str; };
//图表文字格式化
let textFormatter = function(e) {
let newStr = " ";
let start, end;
let name_len = [图片上传失败...(image-236576-1592379384926)]
e.name.length; //每个内容名称的长度
let max_name = 6; //每行最多显示的字数
let new_row = Math.ceil(name_len / max_name); // 最多能显示几行,向上取整比如2.1就是3行
if (name_len > max_name) {
//如果长度大于每行最多显示的字数
for (let i = 0; i < new_row; i++) {
//循环次数就是行数
let old = ""; //每次截取的字符
start = i * max_name; //截取的起点
end = start + max_name; //截取的终点
if (i == new_row - 1) {
//最后一行就不换行了
old = [图片上传失败...(image-2bd6fd-1592379384926)]
e.name.substring(start);
} else {
old = [图片上传失败...(image-699162-1592379384926)]
e.name.substring(start, end) + "\n";
}
newStr += old; //拼接字符串
}
} else {
//如果小于每行最多显示的字数就返回原来的字符串
newStr = [图片上传失败...(image-c78a08-1592379384926)]
e.name;
}
return newStr;
};