Michael
Michael

Reputation: 75

Highcharts - Plot by week with and label formatter

I'm trying to create a project scheduling plot using Highcharts and I'm having a bit of an issue separating the values I want to plot from the axis labels. For example, I want a task to start in week 20 of 2016 so what I have been doing is just concatenating the year and week into: "201620" and then turning it into a category. For my labels I simply split off the last two digits from the first four so it looked like "2016-20". I accomplished this by using the label formatter code in the yAxis portion of the code:

formatter: function() {
  var FullDate = this.value.toString();
  var FiscalYear = FullDate.substring(0, 4);
  var WorkWeek = FullDate.substring(4, 6);
  return FiscalYear + '-' + WorkWeek;
}

This works great as long as all the tasks happen within the same year (see fiddle).

My problem is what to do when 2017 comes around (there shouldn't be 99 weeks in the year, see fiddle). I therefore am converting the work weeks into an auto-calculated integer but I still want my plots to display "2016-20".

So my question is: How can I plot integers but display separate text on an axis?

Link to working example.

Any help would be appreciated!

Upvotes: 1

Views: 416

Answers (1)

Michael
Michael

Reputation: 75

I added an array at that stored my axis label and I think I solved my issue. Link to fiddle here.

var WorkWeekLabels = {
            '1967' : '2016 - 23',
            '1968' : '2016 - 24',
            '1969' : '2016 - 25',
            '1970' : '2016 - 26',
            '1971' : '2016 - 27',
            '1972' : '2016 - 28',
            '1973' : '2016 - 29',
...etc...
}

This post pretty much solved it for me.

Upvotes: 1

Related Questions