在highcharts类别中显示月份和日期

时间:2015-11-13 11:31:33

标签: javascript jquery highcharts

我正在尝试创建一个高图,我正在使用这个时间,我有一些类似的东西:

Categories = ["2015-10-31", "2015-10-30", "2015-11-09", "2015-11-08", "2015-11-07", "2015-11-06", "2015-11-10", "2015-11-05", "2015-11-04", "2015-11-12", "2015-11-03", "2015-11-11", "2015-11-02", "2015-11-01", "2015-11-13"]

我需要绘制类似的类别:

31 oct,30 oc​​t 09 nov,08Nov 07Nov 06Nov 这样的事情

我怎样才能实现这个目标?

1 个答案:

答案 0 :(得分:0)

创建月份数组,对类别执行foreach循环,对日期进行切片并使用月份数组中的名称替换月份

   var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

    Categories=    ["2015-10-31", "2015-10-30", "2015-11-09", "2015-11-08", "2015-11-07", "2015-11-06", "2015-11-10", "2015-11-05", "2015-11-04", "2015-11-12", "2015-11-03", "2015-11-11", "2015-11-02", "2015-11-01", "2015-11-13"]
    newcat =[];
    $.each(Categories,function(i,v){
     newcat.push(v.slice(-2)+months[parseInt(v.slice(5,8)+1)]);
    });

然后在你的char中用newcat替换Categories

jsfiddle:http://jsfiddle.net/e2bm7wu8/4/