var abilityDifferenceEchart;

function echartResize(){
	abilityDifferenceEchart.resize();
}
function getAbilityDifference(scoreData1){
	note(scoreData1,'ability');
	scoreData1.splice(scoreData1.length-1);
	
	var ooo=(vm.params_selected.jp_contrastStatistic==""?0:1);
	var scoreData = [];
	var tempLegendArr1=[],tempLegendArr2=[],tempLegendArr3=[],tempLegendArr4=[];
	for(var i=0;i<scoreData1.length;i++){
		var sdata = scoreData1[i];
		var scoRate=(ooo==1)?sdata.contrast_scoreRate:sdata.scoreRate;
		// console.log();
		if(sdata.difference>=0&&scoRate>=50) tempLegendArr1.push(sdata);
		if(sdata.difference>=0&&scoRate<50) tempLegendArr2.push(sdata);
		if(sdata.difference<0&&scoRate<50) tempLegendArr3.push(sdata);
		if(sdata.difference<0&&scoRate>=50) tempLegendArr4.push(sdata);
		if(i==scoreData1.length-1){
			scoreData=tempLegendArr1;
			for(var p=0;p<tempLegendArr4.length;p++){
				scoreData.push(tempLegendArr4[p]);
			}
			for(var p=0;p<tempLegendArr2.length;p++){
				scoreData.push(tempLegendArr2[p]);
			}
			for(var p=0;p<tempLegendArr3.length;p++){
				scoreData.push(tempLegendArr3[p]);
			}
		}
	}
	
	var bodyWidth = $(window).width();
	var height = bodyWidth*echartScale-60;
	var countOfLie = Math.floor(bodyWidth/50);
	var gridBottomHeight=(Math.ceil(scoreData.length/countOfLie)*30<=60?60:Math.ceil(scoreData.length/countOfLie)*30);
	$("#differenceDiv").width(bodyWidth);
	$("#differenceDiv").height(height+gridBottomHeight);
	// console.log("3:"+$("#differenceDiv").width()+"--"+bodyWidth*echartScale+"---"+gridBottomHeight+"---"+$("#differenceDiv").height());
	document.getElementById("differenceDiv").removeAttribute("_echarts_instance_");
	abilityDifferenceEchart = echarts.init(document.getElementById('differenceDiv'));
	// 指定图表的配置项和数据
	var option = {
		color: ['#FF9132', '#B4E04F', '#C3E0FE', '#B6A2DE'],
		title: {
			textStyle:{
				color:['#48C6FF']
			}
		},
		dataset: {},
		grid: {
		},
		legend: {
			show:true,
			// backgroundColor:'#ff0000',
			
			// bottom:'-30',
			// orient: 'vertical',
			// x: 'right',
			y: 'bottom',
			// height:300,
			data: []
		},
		tooltip: {
			trigger: 'item',
			formatter: function(params) {
				if((params['value']==40||params['value']==80)&&params['color']=='#f00'){
					return "难度："+params['value']+"%";
				}else if(params['value']==0&&params['color']=='#f00'){
					return "得分率差距："+params['value']+"%";
				}else{
					var res = "";
					res ="能力点：" + params.data[7] + "<br/>";
					res +="题号：";
					var tihaoArr=params.data[8].split(",");
					for(var i=0;i<tihaoArr.length;i++){
						res += tihaoArr[i].split("-")[1];
						if(i%2==1){
							res +="<br/>";
						}
					}
					if(tihaoArr.length%2==1){
						res +="<br/>";
					}
					res +="满分：" + params.data[5] + "<br/>";
					res += "教学单位得分率：" + params.data[9] + "%<br/>";
					if(ooo==1){
						res += "对比对象得分率：" + params.data[0] + "%<br/>";
					}
					res += "得分率差距：" + params.data[1] + "%<br/>"
					return res;
				}
			},
			textStyle:{
				fontSize:10
			}
		},
		xAxis: {
			// nameLocation:'end',
			nameTextStyle: { /*横坐标名称样式*/
				color: '#48C6FF',
				padding:[10,0,0,0]
			},
			axisLine: { /*横坐标轴线*/
				show: true,
				lineStyle: {
					color: '#DCDCDC',
				}
			},
			axisTick: { /*横坐标刻度线*/
				show: false,
			},
			splitArea: { // 图表背景网格的颜色
				show: false,
				interval: 0,
				areaStyle: {
					color: ['#FAFAFA', "#F0F5F9"]
				}
			},
			axisLabel: { /*横坐标标签颜色*/
				show: true,
				// interval: 0,
				color: '#000000',
				formatter: '{value} %'
			},
			splitLine: { // 图表背景网格线的颜色
				show: false,
				lineStyle: {
					color: '#DCDCDC',
				}
			},
			boundaryGap: false,
			max:100,
			min:0
		},
		
		yAxis: {
			nameTextStyle: { /*纵坐标名称样式*/
				color: '#48C6FF',
			},
			axisLine: { /*纵坐标坐标颜色*/
				show: true,
				lineStyle: {
					color: '#DCDCDC',
				}
			},
			splitLine: { // 图表背景网格线的颜色
				show: false,
				lineStyle: {
					color: '#DCDCDC',
				}
			},
			axisLabel: { /*横坐标标签颜色*/
				show: true,
				interval: 0,
				color: '#000000',
				formatter: '{value} %'
			},
			scale: true /*纵坐标自适应*/
		},
		graphic: [],
		series: [
			
		]
	};
	option.title.text="能力点：难度-差距二维图";
	option.title.x="center";
	option.xAxis.name="难度";
	option.yAxis.name="得分率差距";
	
	var hh=(Math.ceil(scoreData.length/countOfLie)*30<=60?60:Math.ceil(scoreData.length/countOfLie)*30)+10;
	var graphicArr=[];
	if(tempLegendArr4.length!=0){
		var graphicObj={
			type:'text',right: '10%',bottom: hh,
			style: {text: ['难度较小/相对薄弱点'],fill:'#fa4343'}
		};
		graphicArr.push(graphicObj);
	}
	if(tempLegendArr4.length!=0){
		var graphicObj={
			type:'text',right: '8%',bottom: hh,
			style: {text: ['难度较小\n相对薄弱点'],fill:'#fa4343'}
		};
		graphicArr.push(graphicObj);
	}
	if(tempLegendArr3.length!=0){
		var graphicObj={
			type:'text',left: '12%',bottom: hh,
			style: {text: ['难度较大\n相对薄弱点'],fill:'#FF9132'}
		};
		graphicArr.push(graphicObj);
	}if(tempLegendArr2.length!=0){
		var graphicObj={
			type:'text',left: '12%',top: '15%',
			style: {text: ['难度较大\n相对闪光点'],fill:'#3cb9fc'}
		};
		graphicArr.push(graphicObj);
	}if(tempLegendArr1.length!=0){
		var graphicObj={
			type:'text',right: '8%',top: '15%',
			style: {text: ['难度较小\n相对闪光点'],fill:'#50c48f'}
		};
		graphicArr.push(graphicObj);
	}
	option.graphic=graphicArr;
	var legendArr=[],seriesArr=[],colorArr=[];
	for(var i=0;i<scoreData.length;i++){
		var sdata = scoreData[i];
		legendArr.push(sdata.num);
		
		var seriesObj={
			type:'scatter',
			name:sdata.num,
			data:[
					[
						(ooo==1?sdata.contrast_scoreRate:sdata.scoreRate),sdata.difference,
						sdata.average,sdata.contrast_average,sdata.examPaperNum,sdata.fullScore,sdata.abilityNum,sdata.abilityName,sdata.questionName,sdata.scoreRate,sdata.num
					]
			],
			label:{
				show:true,
				formatter:function(params){
					return params.data[10];
				}
			},
			itemStyle:{
				color:function(params){
					if(params.data[1]>=0&&params.data[0]>50) return "#50c48f";
					if(params.data[1]>=0&&params.data[0]<=50) return "#3cb9fc";
					if(params.data[1]<0&&params.data[0]>50) return "#fa4343";
					if(params.data[1]<0&&params.data[0]<=50) return "#FF9132";
				}
			},
			symbolSize:5*Math.pow(sdata.fullScore,0.5),
			markLine:{
				symbol:'none',
				data : [
					{lineStyle:{type:"solid",color:"#f00",},label:{show:false,},yAxis:0},
					{lineStyle:{type:"solid",color:"#f00",},label:{show:false,},xAxis:50},
				]
			}
		};
		
		seriesArr.push(seriesObj);
		
		var scoRate=(ooo==1)?sdata.contrast_scoreRate:sdata.scoreRate;
		var color="";
		if(sdata.difference>=0&&scoRate>=50) color="#50c48f";
		if(sdata.difference>=0&&scoRate<50) color= "#3cb9fc";
		if(sdata.difference<0&&scoRate<50) color= "#FF9132";
		if(sdata.difference<0&&scoRate>=50) color= "#fa4343";
		colorArr.push(color);
	}
	option.series=seriesArr;
	option.legend.data=legendArr;
	option.color=colorArr;
	
	option.grid.bottom=(Math.ceil(scoreData.length/countOfLie)*30<=60?60:Math.ceil(scoreData.length/countOfLie)*30)+20;
	
	// console.log(option.grid.bottom);
	// 使用刚指定的配置项和数据显示图表。
	// abilityDifferenceEchart.clear();
	abilityDifferenceEchart.setOption(option,true);
}