下面是函数中,通过函数计算得到gwp的值并判断绘图。
后面我想把这个计算得到的gwp的值直接在其他函数中调用,应该怎么改
比如gwp改成全局变量,麻烦指导下,有代码就更好
$(function(){
var dom = document.getElementById("box4");
var myChart = echarts.init(dom);
var app = {};
option = null;
var y_f = [];
//全局变量,wgid在gognweizongtu.js中获取
var gwp = 0;
var xishu = [0.4,0.2,0.3,0.1];
var pjx = ["gzp","gyp","wlp","ryp"];
var pj = {"gongzhuang":"OK", "gongyi": "OK", "wuliao": "OK", "renyuan": "OK"};
var guige = [90, 90, 80, 75,85];
var xiang = ["gongzhuang","gongyi","wuliao","renyuan"];
for (var i = 0 ; i< xiang.length ; i++) {
var lent = data[xiang[i]].y.length ;
var ind = lent - 1 ;
y_f.push(data[xiang[i]].y[ind]);
if (data[xiang[i]].y[ind] < guige[i]){
pj[xiang[i]] = "NOK";
}
document.getElementById(pjx[i]).innerHTML = pj[xiang[i]];
gwp += y_f[i]*xishu[i];
}
y_f.push(88);
if (gwp > 85.5){
document.getElementById("gwpj").innerHTML ="OK";
}
gwp = gwp.toFixed(2);
document.getElementById("gwp").innerHTML =gwp;
document.getElementById("jinri").innerHTML =gwp;
document.getElementById("zuori").innerHTML =gwp;
document.getElementById("benzhou").innerHTML =gwp;
document.getElementById("lishi").innerHTML =gwp;
document.getElementById("gwp1").innerHTML =gwp1;
/*绘图代码省略*/
};
if (option && typeof option === "object") {
myChart.setOption(option, true);
}
})
请采纳