/**
 * 数据库运行
 */
function load() {
			var i ;
			$.ajax({
				method : "post",
				url : "/pqs9900/database/getDatabaseRunning",
				beforeSend: function () {  
	                i = ityzl_SHOW_LOAD_LAYER();  
	            },
	            error:function(data) {
                    layer.msg("暂无数据", {
                        icon : 5,
                        time : 3000
                    });
					//***********关闭loading
		        	ityzl_CLOSE_LOAD_LAYER(i); 
	            },
				success : function(data) {
						var info = $.parseJSON(data);
						if (info.code == 500) {
							//没有数据
							initTable(null);
						} else {
							initTable(info);
						}
					//***********关闭loading
		        	ityzl_CLOSE_LOAD_LAYER(i);
				}
			}); 
	}
	$(document).ready(function() {
		load();
	});
	
	$("#query").click(function(){
		load();
	});
function initTable(data){
	    var x=[];
	    var y=[];
	    for (var i=0;i<data.length;i++){
	    	x.push(data[i][0]);
	    	y.push(parseFloat(data[i][5]));
		}
        var height=$(window).height();
		var heightTemp=screen.height;
		var length;
		if(heightTemp===768){
			length=3;
		}else if(heightTemp<=733){
			length=2;
		}else if(heightTemp===1050){
			length = 6;
		}
		else{
			length=4;
		}
		var p=$("#roleJ").val();
		 $('#vdlist').dataTable().fnClearTable(); 
		if(p=="Npro"){
			var table=$('#vdlist').DataTable({
                "scrollY": "200px",
				destroy : true,
				data : data,
                paging: false,
                alengthMenu:false,
		        language : {
					url:'/pqs9900/json/chine.json'
				},
			});
			new $.fn.dataTable.Buttons(table, {
				buttons: [
					 {
				            extend: 'csv',//导出格式
				            title:'数据库列表',//导出csv名称
				            exportOptions:{ 
					        	columns :[0,1,2,3,4,5],//导出需要的列
					        	format:{
					        		body:function(data){//对导出内容的筛选 data 表格内容 rid 行索引 cid 列索引
					        				return data;
					        		}
					        	}
					        }
				     }
		        ]
			} );
			modifyCss(table);
            $("#container").css("height",height-220);
            //画图
            var chart = Highcharts.chart('container', {
                credits: {
                    enabled: false
                },
                chart: {
                    type: 'column'
                },
                title: {
                    text: ''
                },
                xAxis: {
                    categories: x
                },
                yAxis: [{
                    min: 0,
                    title: {
                        text: '数据库使用率(%)'
                    }
                }],
                legend: {
                    shadow: false
                },
                tooltip: {
                    shared: true
                },
                plotOptions: {
                    column: {
                        grouping: false,
                        shadow: false,
                        borderWidth: 0
                    }
                },
                series: [{
                    name: '数据库使用率(%)',
                    color: green,
                    data: y,
                    tooltip: {
                        valueSuffix: '%'
                    },
                    pointPadding: 0.3,
                    pointPlacement: -0.2
                }]
            });
		}else{
			var table=$('#vdlist').DataTable({
				destroy : true,
                scrollY: 130,
				data : data,
                paging: false,
                info:false,
                alengthMenu:false,
		        language : {
					url:'/pqs9900/json/chine.json'
				},
			});
			new $.fn.dataTable.Buttons(table, {
				buttons: [
					 {
				            extend: 'csv',//导出格式
				            title:'数据库列表',//导出csv名称
				            exportOptions:{ 
					        	columns :[0,1,2,3,4,5,6,7,8,9,10,11,12],//导出需要的列
					        	format:{
					        		body:function(data){//对导出内容的筛选 data 表格内容 rid 行索引 cid 列索引
					        				return data;
					        		}
					        	}
					        }
				     }
		        ]
			} );
			modifyCss(table);
            $("#container").css("height",height-220);
            //画图
            var chart = Highcharts.chart('container', {
                credits: {
                    enabled: false
                },
                chart: {
                    type: 'column'
                },
                title: {
                    text: '数据库使用情况'
                },
                xAxis: {
                    categories: x,
                },
                yAxis: [{
                    min: 0,
                    title: {
                        text: '数据库使用率(%)'
                    }
                }],
                legend: {
                    shadow: false
                },
                tooltip: {
                    shared: true,
                    formatter:function () {
                        var x,y2;
                            x="表空间名称："+this.points[0].x
                            y2="数据库使用率:"+this.points[0].y+"%"
                            return x+'<br>'+y2;
                    }
                },
                plotOptions: {
                    column: {
                        grouping: false,
                        shadow: false,
                        borderWidth: 0
                    }
                },
                series: [{
                    name: '数据库使用率',
                    color: green,
                    data: y,
                    tooltip: {
                        valueSuffix: '%'
                    },
                }]
            });
		}
}
function modifyCss(table){
	table.buttons().container().css("display","inline-block");
	table.buttons().container().css("float","right");
	table.buttons().container().css("left","4px");
	table.buttons().container().find("a").prepend("<i class='glyphicon glyphicon-share'></i>");
	table.buttons().container().appendTo('.header');
}