开发者

highcharts datetime x-axis custom formatting

I would like to have just the first letter of each weekday as the x-axis, ie M T W T F S S repeated. Currently you can set dateTimeLabelFormats, which I've set to use %a, which is the dateFormat for short weekday (Mon Tues Wed etc). How can I just use the first开发者_StackOverflow社区 letter?

Here's my code (I'm using Lazy Highcharts in rails)

 f.xAxis({type: 'datetime', tickInterval: 24*3600*1000, dateTimeLabelFormats: {
        day: '%a',
        week: '%a'}
        })

Thanks.


In the label -> formatter for xAxis, use dateFormat function to get the month and then use the substring function to get the first letter and return that letter as follows -

xAxis: {        
    type: 'datetime',
    labels: {
        formatter: function() {
            var monthStr = Highcharts.dateFormat('%b', this.value);
            var firstLetter = monthStr.substring(0, 1);
            return firstLetter;
        }
    }
},

See it on jsfiddle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜