var picHeight;
var piWidth;

$(document).ready(function() {
	var height = $("body").height();
	piWidth = $("body").width()-550;
    picHeight = height - 60;
    
	var lineIndex=$("#lineIndex").val();
	lineIndex=filterXSS(lineIndex);
	var endTime=getEndTime();
	var startTime=getStartTime("年份", endTime);

	getEventChance(lineIndex,startTime,endTime);
});

function getEventChance(line_index,startTime,endTime){
	jQuery.ajax({
		type : 'POST',
		dataType : "json",
		data : {
			lineIndex:line_index,
			startTime:startTime,
			endTime:endTime
		},
		cache : false,
		url : '/pqs9200/device/eventChance',
		error : function() {},
		success : function(data) {
			if(data == null){
				layer.msg('加载失败！',{icon:2,time:1000});
			}else{
				var eventValue=data.eventvalue;
				var sisttime = data.sisttime;
				var pereventValue=data.pereventvalue;
				var persisttime = data.persisttime;
				
				initChance(eventValue,sisttime,pereventValue,persisttime);
			}
		}
	});
}

function initChance(eventValue,sisttime,pereventValue,persisttime){
    $("#chance1").css("height", picHeight);
	var option1 = {
			backgroundColor: '#f9f9f9',//背景色,
		    title : {
		        text: '暂降幅值的概率分布函数',
		        x : 'center'
		    },
			tooltip : {
				trigger : 'axis',
	            formatter:'暂降幅值: {b0}<br />概率分布: {c0}%'
			},
		    legend: {
		    	show:true,
		    	left:10,
		        data:['概率分布','占比']
		    },
		    toolbox: {
		        show : true,
		        right:'5%',
		        feature : {
		            saveAsImage : {show: true}
		        }
		    },
		    calculable : true,
		    grid:{
		        left:'5%',
		        right:'5%'
		    },
		    xAxis : [
		        {
		            type : 'category',
		            boundaryGap : false,
		            name : '暂降幅值',
		            nameLocation : 'center',
		            nameGap : 20,
		            nameTextStyle :{
		            	fontSize :15
		            },
		            data : ['0','10%','20%','30%','40%','50%','60%','70%','80%','90%']
		        }
		    ],
		    yAxis : [
		        {
		            type : 'value',
		            name : '概率分布',
		            nameLocation : 'center',
		            nameGap : 40,
		            nameTextStyle :{
		            	fontSize :15
		            },
		            axisLabel : {
		                formatter: '{value} %'
		            }
		        },
		        {
		            type : 'value',
		            name : '占比',
		            nameLocation : 'center',
		            nameGap : 40,
		            nameTextStyle :{
		            	fontSize :15
		            },
		            axisLabel : {
		                formatter: '{value} %'
		            }
		        }
		    ],
		    series : [
		        {
		            name:'概率分布',
		            type:'line',
		            data:eventValue
		        },
		        {
		            name:'占比',
		            type:'bar',
		            data:pereventValue,
		            barWidth:30
		        }
		    ]
		};

    $("#chance2").css("height", picHeight);
	var option2 = {
			backgroundColor: '#f9f9f9',//背景色,
		    title : {
		        text: '持续时间的概率分布函数',
		        x : 'center'
		    },
		    legend: {
		    	show:true,
		    	left:10,
		        data:['概率分布','占比']
		    },
		    toolbox: {
		        show : true,
		        right:'5%',
		        feature : {
		            saveAsImage : {show: true}
		        }
		    },
			tooltip : {
				trigger : 'axis',
	            formatter:'持续时间: {b0}s<br />概率分布: {c0}%'
			},
		    calculable : true,
		    grid:{
		        left:'5%',
		        right:'5%'
		    },
		    xAxis : [
		        {
		            type : 'category',
		            boundaryGap : false,
		            name : '暂降持续时间(s)',
		            nameLocation : 'center',
		            nameGap : 20,
		            nameTextStyle :{
		            	fontSize :15
		            },
		            data : ['0.01','0.1','0.25','0.5','1','3','20','60','180']
		        }
		    ],
		    yAxis : [
		        {
		            type : 'value',
		            name : '概率分布',
		            nameLocation : 'center',
		            nameGap : 40,
		            nameTextStyle :{
		            	fontSize :15
		            },
		            axisLabel : {
		                formatter: '{value} %'
		            }
		        },
		        {
		            type : 'value',
		            name : '占比',
		            nameLocation : 'center',
		            nameGap : 40,
		            nameTextStyle :{
		            	fontSize :15
		            },
		            axisLabel : {
		                formatter: '{value} %'
		            }
		        }
		    ],
		    series : [
		        {
		            name:'概率分布',
		            type:'line',
		            data:sisttime
		        },
		        {
		            name:'占比',
		            type:'bar',
		            data:persisttime,
		            barWidth:30
		        }
		    ]
		};
	
    var chance1 = echarts.init(document.getElementById('chance1'));
    chance1.setOption(option1);
    
    var chance2 = echarts.init(document.getElementById('chance2'));
    chance2.setOption(option2);
}