/*
 *  画饼图
 *  @param item echart实例
 *  @param data 画图需要的数据
 */
function drawPie(item,data){
	var option = {
		//backgroundColor:"rgba(255,255,255,0.5)",
		tooltip:{
			trigger:'item',
			formatter:"{a}<br/>{b}：{c}（{d}%）"
		},
		legend:{
			orient:'vertical',
			x:'left',
			data:data.legend,
			textStyle:{
				color:"#fff"
			}
		},
		series:[{
			name:'任务情况',
			type:'pie',
			radius:['50%','80%'],
			avoidLabelOverlap:false,
			label:{
				normal:{
					show:false,
					position:'center'
				},
				emphasis:{
					show:true,
					textStyle:{
						fontSize:'16',
						fontWeight:'bold'
					}
				}
			},
			labelLine:{
				normal:{
					show:false
				}
			},
			data:data.data
		}]
	};
	
	item.setOption(option);
}
/*
 *  画柱状图
 *  @param item echart实例
 *  @param data 画图需要的数据
 */
function drawBar(item,data){
	var option = {
		grid:{
			bottom:20,
		},
		tooltip:{
			trigger:'axis',
			formatter:function(d,ticket,callback){
				for(var i=0;i<d.length;i++){
				   var res = '完成任务情况:<br/>'+d[i].name;
				   var index = d[i].dataIndex;
				   res += '<br/>总任务数:'+data.data.arr1[index]+'<br/>已完成任务数:'+data.data.arr2[index];
				}
				return res;
			}
		},
		xAxis:[{
			data:data.xaxis,
			axisLabel:{
				textStyle:{
					color:"#fff"
				}
			}
		},{
		    type:'category',
			axisLine:{show:false},
			axisTick:{show:false},
			axisLabel:{show:false},
			splitArea:{show:false},
			splitLine:{show:false},
			data:data.xaxis
		}],
		yAxis:{
			axisLabel:{
				textStyle:{
					color:"#fff"
				}
			}
		},
		series:[{
			name:'任务总数',
			type:"bar",
			itemStyle:{normal:{color:function myColor(d){
			   var colorList = ['rgba(193,35,43,0.5)','rgba(181,195,52,0.5)','rgba(252,206,16,0.5)','rgba(39,114,123,0.5)','rgba(155,202,99,0.5)','rgba(254,168,145,0.5)','rgba(243,164,59,0.5)'];
			   return colorList[d.dataIndex];
			},
            label:{show:true,position:'top',textStyle:{color:'#fff'}}}},
			data:data.data.arr1
		},{
			name:'已完成任务',
			type:"bar",
			xAxisIndex:1,
			itemStyle:{normal:{color:function myColor(d){
			   var colorList = ['rgba(193,35,43,1)','rgba(181,195,52,1)','rgba(252,206,16,1)','rgba(39,114,123,1)','rgba(155,202,99,1)','rgba(254,168,145,1)','rgba(243,164,59,1)'];
			   return colorList[d.dataIndex];
			},
			label:{show:true,textStyle:{color:'#fff'}}}},
			data:data.data.arr2
		}]
	};
	item.setOption(option);
}

function myColor(i){
   var colorLIst = ['rgba(193,35,43,0.5)','rgba(181,195,52,0.5)','rgba(252,206,16,0.5)','rgba(39,114,123,0.5)','rgba(155,202,99,0.5)','rgba(254,168,145,0.5)','rgba(243,164,59,0.5)'];
   return colorList[i];
}