一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

E解决charts的柱状统计图出现x轴统计时间出现间隔显示的问题

时间:2016-04-22 编辑:简简单单 来源:一聚教程网

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

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

如下图:

 

 


jsp页面代码 的div


               

                项目工程增长
               
ps" style="display: none;" class="index-tips">目前暂无数据 有数据时将为您统计图表

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);
    
}

主要是修改xAxis的boundaryGap:


 xAxis : [
                {
                    type : 'category',
                    data : proCountMonth,
                     boundaryGap : true,  
                    show : true, 
                    axisLabel:{ 
                        interval:0
                    }
                }
            ],

热门栏目