/**
 * Created by Simon on 2017-6-14.
 */
(function(){
    $("#btn-search").on("click",function(){
        if(check_form("myform")){
            $("#myform").submit();
        }
    });

    drawGraph();
    function drawGraph(){
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        var x = $.parseJSON($("#x").val());
        var legend = $.parseJSON($("#legend").val());
        var total = $.parseJSON($("#total").val());
        var l_yield = $.parseJSON($("#yield").val());
        var option = {
            title: {
                text: '经营报表趋势图',
                top: "top",
                left: "center"
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    animation: false
                }
            },
            grid: {x: '7%', y: '7%', width: '85%', height: '70%',top: "15%"},
            xAxis: {
                type : 'category',
                data : x
            },
            yAxis: [{
                type: 'value',
                name: legend[0],
            },{
                type: 'value',
                name: legend[1],
               /*  axisLabel: {
                    formatter:'{value} %'
                }, */
                scale: true,
                boundaryGap: ['20%','20%']
            }],
            series: [{
                name: legend[0],
                type: "bar",
                yAxisIndex: 0,
                data: total,
                itemStyle:{
                    normal:{
                        color: "#00BB00"
                    }
                }
            },{
                name: legend[1],
                type: "line",
                yAxisIndex: 1,
                data: l_yield,
                label:{
                    normal:{
                        show: true
                    }
                },
                lineStyle:{
                    normal:{
                        color: "#D26900"
                    }
                }
            }]
        };
        //console.info(option);
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }
})();