function EchartsBase(){
	//图形容器
	EchartsBase.mainDiv=null;
	//柱图数据格式
	EchartsBase.data={"title":"本周运维告警统计",xAxis: ["监控","NVR","服务器","应用系统"],"legend":[{"name":"Doset","data":[5, 20, 36, 50],"color":"#00accb"},{"name":"Yeland","data":[51, 210, 36, 10],"color":"#fa102a"}]};
	//柱形+折线图数据格式    折线图数据格式
	//EchartsBase.data={"title":"本周运维告警统计",xAxis: ["监控","NVR","服务器","应用系统"],"legend":[{"name":"Doset","data":[5, 20, 36, 50],"color":"green"},{"name":"Yeland","data":[51, 210, 36, 10],"color":"blue"},{"name":"Yeland1","data":[21,12,13,14],"color":"red"}]};
	//饼图数据格式
	//EchartsBase.data={"title":"本周运维告警统计",data:[{name:"直接访问",value:335,color:"red"},{name:"邮件营销",value:310,color:"blue"},{name:"联盟广告",value:234,color:"green"},{name:"视频广告",value:135,color:"yellow"},{name:"搜索引擎",value:1548,color:"pink"}]};

}
//柱形图
//EchartsBase.barChart();
//折线图
//EchartsBase.lineChart();
//柱形+折线图
//EchartsBase.barLineChart();
//饼图
//EchartsBase.pieChart();

EchartsBase.init=function(obj){
	EchartsBase();
	EchartsBase.mainDiv= echarts.init(document.getElementById(obj.id));
	EchartsBase.data= obj.data;
};

//柱形图
EchartsBase.barChart=function(obj){
	EchartsBase.init(obj);
	// 指定图表的配置项和数据
	var seriesArr = [];
	for(var i in EchartsBase.data.legend){
		seriesArr.push({
            name: EchartsBase.data.legend[i].name,
            type: 'bar',
            data: EchartsBase.data.legend[i].data,
            itemStyle:{
            	color: EchartsBase.data.legend[i].color,
            }
        })
	}
    var option = {
        title: {
            text: EchartsBase.data.title
        },
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        legend: {
            data:EchartsBase.data.legend
        },
        xAxis: {
        	type : 'category',
            data:  EchartsBase.data.xAxis
        },
        yAxis: [{type:"value",}],
        series: seriesArr
    };

    // 使用刚指定的配置项和数据显示图表。
    EchartsBase.mainDiv.setOption(option);
};
//折线图
EchartsBase.lineChart=function(obj){
	console.log("obj",obj);
	EchartsBase.init(obj);
	var option = {
		    title: {
		        text: EchartsBase.data.title,
		        left:"30px",
		        textStyle:{
		        	fontSize:"16",
		        	fontWeight:"bold"
		        }
		    },
		    tooltip: {
		        trigger: 'axis'
		    },
		    legend: {
		        data:[EchartsBase.data.legend[0].name]
		    },
		    xAxis:  {
		        type: 'category',
		        boundaryGap: false,
		        data: EchartsBase.data.xAxis
		    }, 
		    yAxis: {
		        type: 'value',
		        axisLabel: {
		            formatter: '{value}'
		        }
		    },
		    series: [
		        {
		            name: EchartsBase.data.legend[0].name,
		            type:'line',
		            areaStyle:{
		            	color:"#d3f1fc",
		            	opacity:0.5
		            },
		            data: EchartsBase.data.legend[0].data,
		            itemStyle:{ normal : {  
                        lineStyle:{  
                            color:EchartsBase.data.legend[0].color
                        }  
                    }},
		            markPoint: {
		            	itemStyle:{
		            		color:"#6bbd6b"
		            	},
		                data: [
		                    {type: 'max', name: '最大值'},
		                    {type: 'min', name: '最小值'}
		                ]
		            }
		        }/*,
		        {
		            name: EchartsBase.data.legend[1].name,
		            type:'line',
		            data: EchartsBase.data.legend[1].data,
		            itemStyle:{ normal : {  
                        lineStyle:{  
                            color:EchartsBase.data.legend[1].color 
                        }  
                    }},
		            markPoint: {
		            	 data: [
			                    {type: 'max', name: '最大值'},
			                    {type: 'min', name: '最小值'}
			                ]
		            }
		        }*/
		    ]
		};

    // 使用刚指定的配置项和数据显示图表。
    EchartsBase.mainDiv.setOption(option);
};
//柱形+折线图
EchartsBase.barLineChart=function(){
	EchartsBase.init(obj);
	var option = {
		    tooltip: {
		        trigger: 'axis',
		        axisPointer: {
		            type: 'cross',
		            crossStyle: {
		                color: '#999'
		            }
		        }
		    },
		    legend: {
		        data:[EchartsBase.data.legend[0].name,EchartsBase.data.legend[1].name,EchartsBase.data.legend[2].name]
		    },
		    xAxis: [
		        {
		            type: 'category',
		            data: EchartsBase.data.xAxis,
		            axisPointer: {
		                type: 'shadow'
		            }
		        }
		    ],
		    yAxis: [
		        {
		            type: 'value',
		            name:EchartsBase.data.legend[0].name,
		            min: 0,
		            max: 250,
		            interval: 50,
		            axisLabel: {
		                formatter: '{value}'
		            }
		        },
		        {
		            type: 'value',
		            name: EchartsBase.data.legend[1].name,
		            min: 0,
		            max: 25,
		            interval: 5,
		            axisLabel: {
		                formatter: '{value} '
		            }
		        }
		    ],
		    series: [
		        {
		            name:EchartsBase.data.legend[0].name,
		            type:'bar',
		            data:EchartsBase.data.legend[0].data,
		            itemStyle:{color:function(params){
		              	 var color= [EchartsBase.data.legend[0].color];
		              	 return color[params.dataIndex];
		               }}
		        },
		        {
		            name:EchartsBase.data.legend[1].name,
		            type:'bar',
		            data:EchartsBase.data.legend[1].data,
		            itemStyle:{color:function(params){
		              	 var color= [EchartsBase.data.legend[1].color];
		              	 return color[params.dataIndex];
		               }}
		        },
		        {
		            name:EchartsBase.data.legend[2].name,
		            type:'line',
		            yAxisIndex: 1,
		            data:EchartsBase.data.legend[2].data,
		            itemStyle:{ normal : {  
                        lineStyle:{  
                            color:EchartsBase.data.legend[2].color
                        }  
                    }}
		        }
		    ]
		};


    // 使用刚指定的配置项和数据显示图表。
    EchartsBase.mainDiv.setOption(option);
};
//饼图
EchartsBase.pieChart=function(obj){
	EchartsBase.init(obj);
	var legendArr=[],seriesArr=[],colorArr=[];
	for(var i=0,len=EchartsBase.data.data.length;i<len;i++){
		legendArr.push(EchartsBase.data.data[i].name);
		seriesArr.push({name:EchartsBase.data.data[i].name,value:EchartsBase.data.data[i].value});
		colorArr.push(EchartsBase.data.data[i].color);
	}
	
	
	var option = {
		    title : {
		        text: EchartsBase.data.title,
		        left:"10px",
		        textStyle:{
		        	color:"black",
		        	fontStyle:"normal",
		        	fontSize:"16px"
		        }
		    },
		    tooltip : {
		        trigger: 'item',
		        formatter: "{a} <br/>{b} : {c} ({d}%)"
		    },
		    legend: {
		        orient: 'vertical',
		        left: '10px',
		        top:"50px",
		    },
		    series : [
		        {
		            name: '故障检测',
		            type: 'pie',
		            radius : '92%',
		            center: ['86%', '50%'],
		            color:colorArr,
		            data:seriesArr,
		            label: {
	                    position: 'inner',
	                    formatter: '{d}%',
	                    align:"center",
	                    fontSize:"12px",
	                    verticalAlign:"bottom"
		            },
		            itemStyle: {
		                emphasis: {
	
		                }
		            }
		        }
		    ]
		};

    // 使用刚指定的配置项和数据显示图表。
    EchartsBase.mainDiv.setOption(option);
};
//饼图
EchartsBase.alarmWorkbenchPieChart=function(obj){
	EchartsBase.init(obj);
	var legendArr=[],seriesArr=[],colorArr=[];
	for(var i=0,len=EchartsBase.data.data.length;i<len;i++){
		legendArr.push(EchartsBase.data.data[i].name);
		seriesArr.push({name:EchartsBase.data.data[i].name,value:EchartsBase.data.data[i].value});
		colorArr.push(EchartsBase.data.data[i].color);
	}
	
	
	var option = {
			title : {
				text: EchartsBase.data.title,
				left:"10px",
				textStyle:{
					color:"black",
					fontStyle:"normal",
					fontSize:"16px"
				}
			},
			tooltip : {
				trigger: 'item',
				formatter: "{a} <br/>{b} : {c} ({d}%)"
			},
			legend: {
				orient: 'horizontal',
				left: '10px',
				top:"50px"
			},
			series : [
			          {
			        	  name: '故障检测',
			        	  type: 'pie',
			        	  radius : '100px',
			        	  center: ['50%', '70%'],
			        	  color:colorArr,
			        	  data:seriesArr,
			        	  label: {
			        		  position: 'inner',
			        		  formatter: '{d}%',
			        		  align:"center",
			        		  fontSize:"12px",
			        		  verticalAlign:"bottom"
			        	  },
			        	  itemStyle: {
			        		  emphasis: {
			        			  
			        		  }
			        	  }
			          }
			          ]
	};
	
	// 使用刚指定的配置项和数据显示图表。
	EchartsBase.mainDiv.setOption(option);
};
//饼图
EchartsBase.circularGraphChart=function(obj){
	EchartsBase.init(obj);
	var option = {
			tooltip : {
				trigger : 'item',
				formatter : "{a} <br/>{b}: {c} ({d}%)"
			},
			legend : {
				orient : 'vertical',
				x : 'left',
				data : []
			},
			series : [ {
				name : '访问来源',
				type : 'pie',
				radius : [ '50%', '70%' ],
				center : [ '50%', '45%' ],
				color : [ '#27a72d', '#ff7a05' ],
				avoidLabelOverlap : false,
				label : {
					normal : {
						show : false,
						position : 'center'
					},
					emphasis : {
						show : true,
						textStyle : {
							fontSize : '20',
							fontWeight : 'bold'
						}
					}
				},
				labelLine : {
					normal : {
						show : false
					}
				},
				data : EchartsBase.data
			} ]
	}
	
	// 使用刚指定的配置项和数据显示图表。
	EchartsBase.mainDiv.setOption(option);
};
