Highcharts - 更改时在x轴上显示年份标签

时间:2013-12-22 20:51:20

标签: highcharts

我有一个场景,我只想在标签中包含年份,例如。

2011年1月,2月,3月,..... 2012年1月,2月,3月,....

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

您可以使用自定义xAxis.labels.formatter

     xAxis: {
        type: 'datetime',
        tickInterval: 2678400000, //tick every month
        labels:{
            formatter: function() {
                var d = new Date(this.value);
                if (d.getUTCMonth() == 0){
                    return Highcharts.dateFormat("%b-%Y",this.value); // if jan display yeat
                }else{
                    return Highcharts.dateFormat("%b",this.value); // just month
                }                       
            }   
        }
    },

小提琴here

enter image description here