Echarts的柱状统计图出现x轴统计时间出现间隔显示的问题

今天在使用Echarts的柱状统计图出现x轴统计时间出现间隔显示的问题:

数据都拿到了,放到Json数组都是完整的, 展现是时候

如下图:

------------------------------------------------------jsp页面代码 的div

<div class="f-r w-b45">
                <div id="proMonthCount" style="min-width: 310px; margin: 0 auto;padding-top:50px;"></div>
                <span class="title-ind-bule">项目工程增长</span>
                <div id="pro_tips" style="display: none;" class="index-tips"><span class="icon-bule-tips"></span>目前暂无数据 有数据时将为您统计图表</div>
</div>

 

------------------------------------------------------js代码

var myChart;

var arrProCount;

var proCountMonth;

var proCount=0;

 

function getProCount(){
    var result = doAjax("POST", WEB_URL + '/views/getProCount', {}, false);
    result = eval("(" + result + ")");
    var results = result.results;
    arrProCount = [];
    proCountMonth = [];
    
    for (var i = 0, j = results.length; i < j; i++) {
        var curr_result = results[i];
        var curr_count = parseInt(curr_result.quantity);
        //var curr_arr = [ curr_result.countMonth, curr_count ];
        
        arrProCount.push(curr_count);
        proCountMonth.push(curr_result.countMonth);
        
        proCount += curr_count;
    }
}

function getProCountChart() {
    if (proCount == 0) {
        $("#pro_tips").show();
        return;
    }
    $("#proMonthCount").css("height", 400);
    
    alert(proCountMonth);
    alert(arrProCount);
    // 基于准备好的dom,初始化echarts图表
    myChart = echarts.init(document.getElementById('proMonthCount'));
    var option = {
            title : {
                text: '项目工程增长'
            },
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data:['项目工程数']
            },
            toolbox: {
                show : true,
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : proCountMonth,
                    
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
               
                {
                    name:'项目工程数',
                    type:'bar',
                    data:arrProCount
                }
            ]
        };
    // 为echarts对象加载数据
    myChart.setOption(option);
    
}

-------------------------------------------------------------------------------------

后来经过不断的调整,边看API,不断的找原因,加了几行代码 就好了

------------------------------------------------修改代码如下:

var myChart;

var arrProCount;

var proCountMonth;

var proCount=0;

 

function getProCount(){
    var result = doAjax("POST", WEB_URL + '/views/getProCount', {}, false);
    result = eval("(" + result + ")");
    var results = result.results;
    arrProCount = [];
    proCountMonth = [];
    
    for (var i = 0, j = results.length; i < j; i++) {
        var curr_result = results[i];
        var curr_count = parseInt(curr_result.quantity);
        //var curr_arr = [ curr_result.countMonth, curr_count ];
        
        arrProCount.push(curr_count);
        proCountMonth.push(curr_result.countMonth);
        
        proCount += curr_count;
    }
}

function getProCountChart() {
    if (proCount == 0) {
        $("#pro_tips").show();
        return;
    }
    $("#proMonthCount").css("height", 400);
    
    alert(proCountMonth);
    alert(arrProCount);
    // 基于准备好的dom,初始化echarts图表
    myChart = echarts.init(document.getElementById('proMonthCount'));
    var option = {
            title : {
                text: '项目工程增长'
            },
            tooltip : {
                trigger: 'axis'
            },
            legend: {
                data:['项目工程数']
            },
            toolbox: {
                show : true,
                feature : {
                    dataView : {show: true, readOnly: false},
                    magicType : {show: true, type: ['line', 'bar']},
                    restore : {show: true},
                    saveAsImage : {show: true}
                }
            },
            calculable : true,
            xAxis : [
                {
                    type : 'category',
                    data : proCountMonth,
                     boundaryGap : true,   
                    show : true,  
                    axisLabel:{  
                        interval:0
                    }
                }
            ],
            yAxis : [
                {
                    type : 'value'
                }
            ],
            series : [
               
                {
                    name:'项目工程数',
                    type:'bar',
                    data:arrProCount
                }
            ]
        };
    // 为echarts对象加载数据
    myChart.setOption(option);
    
}

----------------------------------------------------------------

在此记录下这次解决问题的方案。

 

posted on 2016-03-30 16:05  何甘霖  阅读(3373)  评论(0编辑  收藏  举报