Highstock - display number of week

前端 未结 3 681
盖世英雄少女心
盖世英雄少女心 2021-01-22 17:23

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         


        
3条回答
  •  梦谈多话
    2021-01-22 18:05

    You can add it using dateFormats, for example: http://jsfiddle.net/EkAnm/

    Highcharts.dateFormats = {
        W: function (timestamp) {
            var date = new Date(timestamp),
                day = date.getUTCDay() == 0 ? 7 : date.getUTCDay(),
                dayNumber;
            date.setDate(date.getUTCDate() + 4 - day);
            dayNumber = Math.floor((date.getTime() - new Date(date.getUTCFullYear(), 0, 1, -6)) / 86400000);
            return 1 + Math.floor(dayNumber / 7);
    
        }
    }
    

    Then use it in or format or dateFormat():

    xAxis: {
            tickInterval: 7 * 24 * 36e5, // one week
            labels: {
                format: '{value:Week %W/%Y}'
            }
        },
    

提交回复
热议问题