How can I show the week number for the date in Highstock (not Highcharts!)?
My SQL looks like this
select unix_timestamp(date)*1000 week
To keep weeks and years consistent, I tend to use ISO-8601 standard when dealing with week numbering.
With Pawel answer and the js code from this blog, I set up the following solution.
Highcharts.dateFormats = {
V: function (timestamp) {
var target = new Date(timestamp);
var dayNr = (target.getDay() + 6) % 7;
target.setDate(target.getDate() - dayNr + 3);
var firstThursday = target.valueOf();
target.setMonth(0, 1);
if (target.getDay() != 4) {
target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
} ,
G: function(timestamp) {
var target = new Date(timestamp);
target.setDate(target.getDate() - ((target.getDay() + 6) % 7) + 3);
return target.getFullYear();
}
};
%V and %G respects the strftime format used in highstock.