Scales - Custom time unit: show 4 Quarters of a year


I’m refering to this part of the documentation:

var monthScaleTemplate = function (date) {
var dateToStr ="%M");
var endDate =, 2, “month”);
return dateToStr(date) + " - " + dateToStr(endDate);
gantt.config.scales = [
{unit: “year”, step: 1, format: “%Y”},
{unit: “month”, step: 3, format: monthScaleTemplate},

I have 2 problems with this example which i don’t know how to change:

  1. The custom time unit shows Feb-Apr, May-Jul. It does not start with january.
    How to change it to show Jan-Mar, Apr-Jun, etc. ?

  2. Instead of the months i would just like to display Q1, Q2, Q3, Q4 in the custom scale.

thanks for your help!


Hello Jochen,
Timeline and scales start from a date. In the sample, there is the month scale with the step parameter. With that combination, Gantt covers 3 months instead of one. And there is a template that shows the first and third months.
You can use the month scale without the step parameter and calculate the quarter number. Here is an example of how it might be implemented:

If you need the quarter scale to cover 3 months, you need to create a custom scale unit. Here is an example of how it might be implemented:
And here is an explanation of how it works.
We don’t modify the initial date, so we return it as it is: = function(date){
  return date;

All calculations are made in the function.
The year quarter scale means that all cells should be equal (3 months). But most likely, the first and last scale cells will differ from others. It happens because they start on a date that is different from the quarter start date.
So, we calculate the quarter dates, check which quarter the cell belongs to and return the quarter date.


Great, this works perfectly fine!

Thanks Ramil


Hi, I tested the second snippet and it works great. I want to show years and quarters only, not months, but if I remove the month line (check it in the snippet), the gantt only shows the last two quarters, but miss the first two ones. Is there any way of fix it? Thanks!


You can try using scale_offset_mimimal config, it controls the padding of the time scale from the earliest and the latest dates of the dataset:

gantt.config.scale_offset_minimal = false;

Live demo:

Alternatively, you may need to set the time range explicitly, please check this article:

Btw, quarter units are now supported out of the box, so you probably don’t need to implement year_quarter_start and add_year_quarter functions:

gantt.config.scale_offset_minimal = false;
gantt.config.scales = [
  {unit: 'year', step: 1, format: '%Y'},
  {unit: 'quarter', step: 1, format: function(date){
      return "Q" + (Math.floor((date.getMonth() / 3)) + 1)


Thanks Aliaksandr, I’l take a look.
Actually, I’m trying to set a semester scale, adapting this sample, but I get the same issue.


Hi, John!
I’ll duplicate my reply from disqus, in case anyone else would follow this thread:

you’ll need to define a custom time unit for that:

which is fairly simple, you just need to define two method: = function(date){
	// define start dates for each semester
	if(date.getMonth() < 6){
		//the first semester - 1st of January 
		return new Date(date.getFullYear(), 0, 1); 
		//the second semester - 1st of July 
		return new Date(date.getFullYear(), 6, 1);
}; = function(date, inc){
	var start = Date(date));
	return, 6*inc, "month");

Then you’ll be able to use the semester unit in code:

gantt.config.scales = [
	{unit: 'year', step: 1, format: '%Y'},
	{unit: 'semester', step: 1, format: function(date){
		if(date.getMonth() < 5){
			return "I";
			return "II";

Live demo: