VUE2.0+Element-UI+Echarts封装的组件实例

2020-06-16 05:58:16易采站长站整理

}
if (num != undefined) {
result = num + result;
}
if (n) {
result = "-" + result;
}
if(s=='.0'){
return result;
}
return result + s;
}
// 千分位与单位处理
function cellsDeal(num,unit) {
if (typeof (num) == 'undefined') {
num = "";
}
if(num===''){
return num;
}
num = num + '', result = '';
if (unit=='%') {
num=parseFloat(num)*100;
num = num.toFixed(1) + '';
if(num.indexOf(".")!=-1){
return num.substring(0,num.indexOf(".")+2)+"%";
}else{
return num+"%";
}
}
var s = "";
if (num.indexOf('.') > -1) {
num=parseFloat(num).toFixed(1);
s = num.substring(num.indexOf('.'), num.length); //小数位
num = num.substring(0, num.indexOf('.')); //整数位
}
var n = false;
if (num.indexOf('-') > -1) {
num = num.substring(1);
n = true;
}
while (num.length > 3) {
result = ',' + num.slice(-3) + result;
num = num.slice(0, num.length - 3);
}
if (num != undefined) {
result = num + result;
}
if (n) {
result = "-" + result;
}
if(unit.indexOf("/")!=-1){
s=s.substring(0,2);
}else{
s="";
}
return result + s;
}
/*动态计算echarts的grid属性 */
function computerGrid(options){
// 图宽度 默认
var chartWidth = 810;
// 图例占宽度比
var legendWidth = chartWidth * 0.8;
// 图高度默认
var chartHeight = 250;
// 图中grid离容器下边距高度默认
var bottomHeight = 25;
// 图中grid离容器上边距高度默认
var topHeight = 40;
// 根据x轴刻度数量 算宽度,如果超过默认 则使用计算值
if (options.xAxis[0].data.length * 30 - chartWidth > 0) {
chartWidth = options.xAxis[0].data.length * 30;
}
// x轴刻度 最长的长度值
var maxLength = 0;
var legendCount = 8;
if (options.xAxis[0].data.length > legendCount) {
options.xAxis[0].data.forEach(function(val) {
if (maxLength < val.length) {
maxLength = val.length;
if (/[^u0000-u00FF]/.test(val)) {
// 计算图中grid离容器下边距高度
bottomHeight = maxLength * 14;
} else {
// 计算图中grid离容器下边距高度
bottomHeight = maxLength * 13.5;
}
}
});
}
var tmpWidth = 0;
options.legend.data.forEach(function(val) {
if (/[^u0000-u00FF]/.test(val)) {
tmpWidth += val.length * 22 + 30;
} else {
tmpWidth += val.length * 11 + 30;
}
});
var rowNum = tmpWidth / legendWidth;
// 根据图例算 图中grid离容器上边距高度
if (rowNum > 1) {
topHeight += (rowNum - 1) * 23;
}
chartHeight += bottomHeight + topHeight;
options.legend['width'] = legendWidth;