Monday, May 20, 2024
125
rated 0 times [  127] [ 2]  / answers: 1 / hits: 26435  / 13 Years ago, fri, october 14, 2011, 12:00:00

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 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.


More From » ruby-on-rails

 Answers
4

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


[#89616] Wednesday, October 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kourtney

Total Points: 368
Total Questions: 103
Total Answers: 85

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
kourtney questions
Sun, Oct 4, 20, 00:00, 4 Years ago
Tue, Oct 29, 19, 00:00, 5 Years ago
Thu, Apr 4, 19, 00:00, 5 Years ago
Fri, Mar 1, 19, 00:00, 5 Years ago
;