将ichartjs的画图封装成一个函数
var drawLineBasic2D = function(projectName, weeks, newBugsNumberArr, closedBugsNumberArr, remainBugsNumberArr){ . . . }将项目名称、刻度水平轴的文本标签数组、数据data数组做为参数传入函数中
在处理传入的数据中
var loadReport = function(projectName) { $.get((data.statusCode === 500) { alert('Wrong Wrong Wrong,please check!!!'); } else { var newBugsNumberArr = [], closedBugsNumberArr = [], remainBugsNumberArr = [], weeks = [], length = data.length; for(var i = 0; i < length; i++){ newBugsNumberArr.push(data[i]['newBugsNumber']); closedBugsNumberArr.push(data[i]['closedBugsNumber']); remainBugsNumberArr.push(data[i]['remainBugsNumber']); weeks.push(data[i]['week']); } drawLineBasic2D(projectName, weeks, newBugsNumberArr, closedBugsNumberArr, remainBugsNumberArr) } }); };其中,’/NextPage/report/data’ 在index.js文件中定义
/** * 请求数据库数据 */ router.get('/NextPage/report/data', function (req, res, next) { jiraMysqlQuery.checkProjectBugNumber(req.param('projectName'), function(error, data) { if(error) { res.send({stateCode: 500}); }else { res.send(data); } }); });回调函数,返回变量data让function(data){} 调用
loadReport函数中的如:
closedBugsNumberArr.push(data[i][‘closedBugsNumber’] 为在Mysql To Charts(三)中读取到的数据库的数组的值
loadReport.js文件中
var loadReport = function(projectName) {};抛出projectName的变量,给其他文件调用