function getStartDate(chooseYear){
    // 按年度来计算的时候，开始时间是该年度7月1号还是到下一个年的6月30号结束
    if(chooseYear == 2016){
        return chooseYear + "-08-01";
    }else{
        return chooseYear+'-07-01';
    }
}
//获取结束时间
function getEndDate(chooseYear){
    chooseYear = parseInt(chooseYear);
    var endDate = new Date((chooseYear+1) + '-06-30'),
        now = new Date();
    if(now <= endDate){
        return now.format("yyyy-MM-dd");
    }else{
        return (chooseYear+1) + '-06-30';
    }
}

/*
 * 获取用来排序的字段值，返回数组
 * 参数： list - 列表， key - 字段的名称 
 */
function getKeyValueArr(list, key){
    var arr = [];
    for(var k in list){
        arr.push(list[k][key]);
    }
    
    return arr;
}

/*
 * 排名
 */
function soreRank(arr){
    var temp = [];
    var lis = [];
    for(var i=0;i<arr.length;i++){
        lis.push(arr[i]);
    }
    lis = _.uniq(lis);
    for(var i=0;i<arr.length;i++){
        temp[i] = lis.indexOf(arr[i])+1;
    }
    
    return temp;
}

/*
 * 绘制饼图
 * arry [{name: '', value: ''}]
 * color ['#ffc800', '#17b3ec']
 */
function drawPieChart(elId, arry, color){
    var myChart = echarts.init(document.getElementById(elId));
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{b} : {c} ({d}%)",
            position: ['50%', '50%']
        },
        color: color,
        series: [
        {
            type:'pie',
            radius: ['80%', '99%'],
            startAngle: 270,
            legendHoverLink: false,
            hoverAnimation: false,
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    textStyle: {
                        color: "#000"
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false 
                }
            },
            data:arry
        }]
    };
    $("#"+elId).removeAttr("_echarts_instance_");
    myChart.setOption(option);
}

/**
 * 绘制柱状图
 */
function drawBarChart(el, xData, yData, color, name){
    var myChart = echarts.init(document.getElementById(el));
       
    // 指定图表的配置项和数据
    var option = {
        tooltip: {
            trigger: 'item'
        },
        toolbox: {
            dataZoom: true,
            show: true,
            orient: 'vertical',
            x: 'right',
            y: 'center'
        },
        grid: {
            left: '20px',
            right: '20px',
            bottom: '20px',
            top: '20px',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            data: xData,
            axisLabel: {
                interval:0,//横轴信息全部显示  
            },
            splitLine: {
                show: false
            }
        }],
        yAxis: [{
            type: 'value',
            splitLine: {show:false}
        }],
        series: [{
            clickable: true,
            name: name,
            itemStyle : { 
                normal: {
                    label : {
                        show: true, position: 'top'
                    },
                    color: color
                }
            },
            barWidth: 20,
            type: 'bar',
            data: yData 
        }]
    };
    
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
