1、定义一个函数
// 字节转换方法,传入byte
function byteConversion(b) {
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let l = 0, n = parseInt(b, 10) || 0;
while (n >= 1024 && ++l) {
n = n / 1024;
}
return (n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
}
2、yAxis中定义
axisLabel: {
formatter: (value) => {
// 这里后台传过来的是MB需要选算成B
const b = value * 1024 * 1024;
return b
}
},
//图片方便理解