//var colors = ['#999999','#FE8E60','#EDD24D','#B4ECE9','#D2B6E9','#B0CDB1','#EB717E','#BF8A9A','#EDC8B5','#A0A0A0'];
var colors = ['#FE8E60','#B4ECE9','#B0CDB1','#FE8E60','#B4ECE9','#B0CDB1','#FE8E60','#B4ECE9','#B0CDB1','#FE8E60'];
var colors2 = ['#FE8E60','#FE8E60','#B4ECE9','#B0CDB1','#FE8E60','#B4ECE9','#B0CDB1','#FE8E60','#B4ECE9','#B0CDB1'];

function trend_pie(title,legend,series,divId){
	var option = {
		    tooltip : {
		        trigger: 'item',
		        formatter: "{a} <br/>{b} : {c} ({d}%)"
		    },
		    legend: {
		    	x : 'center',
		        y : 'bottom',
		        data:legend
		    },
		    calculable : true,
		    series : [
		        {
		            name:title,
		            type:'pie',
		            radius : [30, 70],
		            center : ['50%', 150],
		            roseType : 'area',
		            x: '50%',               // for funnel
		            max: 40,                // for funnel
		            sort : 'ascending',     // for funnel
		            data:series
		        }
		    ],
		    color : colors
		};
		                    
	require(
			[
		        'echarts',
		        'echarts/chart/pie'
		    ],
		    function(orderTrendEC){
		        var myChart = orderTrendEC.init(document.getElementById(divId));
		        var ecConfig = require('echarts/config');   
		        myChart.setOption(option);
		        window.onresize = myChart.resize;
		    }
	);
}


function trend_pie_normal(title,legend,series,divId){
	var option = {
		    tooltip : {
		        trigger: 'item',
		        formatter: "{a} <br/>{b} : {c} ({d}%)"
		    },
		    legend: {
		        orient : 'vertical',
		        x : 'left',
		        data:legend
		    },
		    calculable : true,
		    series : [
		        {
		            name:title,
		            type:'pie',
		            radius : [30, 70],
		            center : ['50%', 150],
		            data:series
		        }
		    ],
		    color : colors
		};
		                    
	require(
			[
		        'echarts',
		        'echarts/chart/pie'
		    ],
		    function(orderTrendEC){
		        var myChart = orderTrendEC.init(document.getElementById(divId));
		        var ecConfig = require('echarts/config');   
		        myChart.setOption(option);
		        window.onresize = myChart.resize;
		    }
	);
}




function trendBarWithLine(legend,xdata,ydata,ys,divId){
	var i = 0,barChart = {
		    tooltip : {
		        trigger: 'axis'
		    },
		    grid: {show:'true',borderWidth:'0'},
		    legend: {
	            data:legend
	        },
		    calculable : true,
		    xAxis : [
		        {
		            type : 'category',
		            axisLabel: {
		                interval: 0,
		                rotate: 30
		            },
		            data : xdata,
		            splitLine:{show: false}//去除网格线
		        }
		    ],
		    yAxis : [
		             {  
		                 type : 'value',  
		                 position: 'left',  
		                 splitNumber: 0.1,  
		                 boundaryGap: [0,1],  
		             },  
		             {  
		                 type : 'value',  
		                 splitNumber: 0.1,  
		                 axisLabel : {  
		                     formatter: function (value) {  
		                         // Function formatter  
		                         return value
		                     }  
		                 },  
		                 splitLine : {  
		                     show: false  
		                 }  
		             }  
		    ],
		    grid: { 
	             y2: 100
	        },
		    series : [
		        {
		            name:legend[0],
		            type:'bar',
		            data:ydata,
		            barWidth : 20 ,//柱图宽度
		            itemStyle:{
			            normal:{
			              color:function (params){
	                        return colors2[i++ % 10];
		                  },
		                  label: {  
                              show: true,//是否展示  
                              textStyle: {  
                                  fontWeight:'bolder',  
                                  fontSize : '12',  
                                  fontFamily : '微软雅黑',  
                              }  
                          } 
			          }
			       }
		        },
	            {
	                name:legend[1],
	                type:'line',
	                yAxisIndex: 1,
	                data: ys,
	                itemStyle:{
			            normal:{
			              color:'#FE8E60'
			          }
			       }
	            }
		    ]
		};
	require(
			[
		        'echarts',
		        'echarts/chart/bar',
		        'echarts/chart/line'
		    ],
		    function(orderTrendEC){
		        var myChart = orderTrendEC.init(document.getElementById(divId));
		        var ecConfig = require('echarts/config');
		        myChart.setOption(barChart);
		    }
	);
}


function trendBar(name,xdata,ydata,divId){
	var i=0,barChart = {
		    tooltip : {
		        trigger: 'axis'
		    },
		    calculable : true,
		    xAxis : [
		        {
		            type : 'category',
		            axisLabel: {
		                interval: 0,
		                rotate: 30
		            },
		            data : xdata,
		            splitLine:{show: false}//去除网格线
		        }
		    ],
		    yAxis : [
		        {
		            type : 'value',
		            splitNumber : 0.1,
		            splitLine:{show: false}//去除网格线
		        }
		    ],
		    grid: { 
	             y2: 100,
	             show:'true',borderWidth:'0'
	        },
		    series : [
		        {
		            name:name,
		            type:'bar',
		            data:ydata,
		            barWidth : 20,//柱图宽度
		            itemStyle:{
			            normal:{
			              color:function (params){
	                        return colors[i++ % 10];
		                  },
		                  label: {  
                              show: true,//是否展示  
                              textStyle: {  
                                  fontWeight:'bolder',  
                                  fontSize : '12',  
                                  fontFamily : '微软雅黑',  
                              }  
                          } 
			          }
			       }
		        }
		    ]
		};
	require(
			[
		        'echarts',
		        'echarts/chart/bar'
		    ],
		    function(orderTrendEC){
		        var myChart = orderTrendEC.init(document.getElementById(divId));
		        var ecConfig = require('echarts/config');
		        myChart.setOption(barChart);
		    }
	);
}

/**
 * 横向的柱状图
 * @param name
 * @param xdata
 * @param ydata
 * @param divId
 */
function trendHorizontalBar(name,xdata,ydata,divId,cur_colors){
	var i=0,option = {
		    tooltip : {
		        trigger: 'axis'
		    },
		    grid: {show:'true',borderWidth:'0', x : 135},
		    calculable : true,
		    xAxis : [
		        {
		            type : 'value',
		            boundaryGap : [0, 0.01],
		            splitLine:{show: false},//去除网格线
		            splitNumber : 0.1
		        }
		    ],
		    yAxis : [
		        {
		            type : 'category',
		            data : ydata,
		            splitLine:{show: false},//去除网格线
		            axisLabel: {
		                textStyle: {
		                    fontSize: 11,
		                    align : 'left'
		                },
		            	margin : 115,
		            	formatter : function (value){
		            		if(value.length > 10){
		            			return value.substring(0, 10) + "..";
		            		}else{
		            			return value;
		            		}
		            		
		            	}
		            }
		        }
		    ],
		    series : [
		        {
		            name:name,
		            type:'bar',
		            barWidth : 10,//柱图宽度
		            data:xdata,
		            itemStyle:{
			            normal:{
			              color:function (params){
			            	if(cur_colors.length > 0){
			            		var color = cur_colors[i++ % cur_colors.length];
			            		return color;
			            	}
		                  },
		                  label: {  
                              show: true,//是否展示  
                              textStyle: {  
                                  fontWeight:'bolder',  
                                  fontSize : '11',  
                                  fontFamily : '微软雅黑',  
                              }  
                          } 
			          }
		            }
		        }
		    ]
		};
	require(
			[
		        'echarts',
		        'echarts/chart/bar'
		    ],
		    function(orderTrendEC){
		        var myChart = orderTrendEC.init(document.getElementById(divId));
		        var ecConfig = require('echarts/config');
		        myChart.setOption(option);
		    }
	);
}