var loadDashBoard = function() {
	setTimeout(
			function() {
				var arg1 = {};
				arg1.action = "queryUserStat";
				global.wssocket.send(JSON.stringify(arg1));
				changeLineContractUseTime($("#lineContractUse")[0].value);
				listNodes();
			}, 500);
};

var changeLineContractUseTime = function(data){
	var time = data.split("天")[0];
	console.log(time);
	global.lineContractUseTime = time;
	setTimeout(function() {
		var arg = {};
		arg.action = "countCMLogByCategory";
		arg.category="setNodeID,updateContract,queryRouteInfo"
		arg.start = getDateDaysBefore(global.lineContractUseTime);
		arg.interval = 24*3600*1000;
		arg.requestID = "changeLineContractUseTime_"+new Date().getTime()+"_"+Math.floor(Math.random()*1000000);
		global.wscallbacks[arg.requestID]=onChangeLineContractUseTime;
		global.wssocket.send(JSON.stringify(arg));
	}, 300);
};
var onChangeLineContractUseTime = function(obj){
    console.log(obj);
    var data = {};
    var  start = getDateDaysBefore(global.lineContractUseTime);

    data.xAxis =[];
    for (var i=0;i<obj.data.setNodeID.length;i++){
        var date = new Date(start);
        data.xAxis.push(date.getMonth()+1+"/"+date.getDate());
        start+=24*3600*1000;
    }
    data.yAxis1 = obj.data.setNodeID;
    data.yAxis2 = obj.data.updateContract;
    data.yAxis3 = obj.data.queryRouteInfo;
    drawDashBoardCMLog(data);
}

var drawDashBoardCMLog = function(data) {
	global.lastData = data;
	console.log("drawDashBoardCMLog");
	$("#dashboardContractExeDiv")
			.html(
					"<div class='col-12' id='dashboardContractExeCanv' style='min-height: 200px; padding: 0px'></div>");
	var xAxisData = data.xAxis;
	var pubEventData = data.yAxis1;
	var trustData = data.yAxis2;
	var wsExecute = data.yAxis3;

	var myChart = echarts.init($("#dashboardContractExeCanv")[0], 'walden');
	var option = {
		title : {
			subtext : '次数'
		},
		tooltip : {
			trigger : 'axis'
		},
		legend : {
			data : [ '节点上线次数', '更新合约次数', '合约路由次数' ],
			y : 'bottom',
		},
		toolbox : {
			show : true,
			feature : {
				dataZoom : {
					yAxisIndex : 'none'
				},
				dataView : {
					readOnly : false
				},
				magicType : {
					type : [ 'line', 'bar' ]
				},
				restore : {},
				saveAsImage : {}
			}
		},
		xAxis : {
			type : 'category',
			boundaryGap : false,
			data : xAxisData
		},
		yAxis : {
			type : 'value',
			axisLabel : {
				formatter : '{value}次'
			}
		},
		series : [ {
			name : '节点上线次数',
			type : 'line',
			data : pubEventData,
			markPoint : {
				data : [ {
					type : 'max',
					name : '最大值'
				}, {
					type : 'min',
					name : '最小值'
				} ]
			},

		}, {
			name : '更新合约次数',
			type : 'line',
			data : trustData,

			markPoint : {
				data : [ {
					type : 'max',
					name : '最大值'
				}, {
					type : 'min',
					name : '最小值'
				} ]
			}
		}, {
			name : '合约路由次数',
			type : 'line',
			data : wsExecute,

			markPoint : {
				data : [ {
					type : 'max',
					name : '最大值'
				}, {
					type : 'min',
					name : '最小值'
				} ]
			}
		} ]
	};
	myChart.setOption(option);
};