NaddyNapz
Posts: 1
Joined: Wed Aug 18, 2021 2:29 pm

Week Indicator on Highcharts

Hello, I am trying to customize my week axis on the Gantt chart.
It is currently starting based on week of the year and I am trying to start my week count from a date I specify.

For example: instead of starting at week 45 calculated from the first of the year. I want to start from week 1 with
a custom start date.. like from today.. week 1, 2 ,3 etc..

Does any one of a way to customize the weeks this way ?

Here is the current code for Gantt Chart Week calculations:

Code: Select all

W: function () {
            var target = new Date(this.valueOf())
            var dayNr = (this.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)
            }
            var retVal = 1 + Math.ceil((firstThursday - target) / 604800000)

            return (retVal < 10 ? '0' + retVal : retVal)
        },
        
User avatar
sebastian.h
Posts: 1734
Joined: Fri Aug 07, 2020 7:08 am

Re: Week Indicator on Highcharts

Hi,
Welcome to our forum and thanks for contacting us with your question.

Generally weeks are calculated automatically but you have the possibility to add any values inside xAxis.dateTimeLabelFormats at a place of the week.

Code: Select all

    xAxis: [{
        dateTimeLabelFormats: {
            week: {
                list: ['week ' + test]
            }
        }
    }],
https://jsfiddle.net/BlackLabel/r9feLmqa/
https://api.highcharts.com/gantt/xAxis. ... belFormats

Other way to edit the xAxis label is to at the chart.events.load
https://jsfiddle.net/BlackLabel/cbeyxLu5/

Let me know if that was what you were looking for!
Best regards.
Sebastian Hajdus
Highcharts Developer

Return to “Highcharts Gantt”