Back to column formats
Column formattingSharePoint Online

Monthly Gantt Chart

This sample demonstrates the display of a monthly Gantt chart. The Gantt chart for the month corresponding to the StartDate value will be shown.

Monthly Gantt Chart formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if([$StartDate],'flex','none')",
    "flex-direction": "column",
    "width": "200px",
    "height": "75px",
    "margin": "5px"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "width": "100%",
        "text-align": "center",
        "font-weight": "bolder"
      },
      "txtContent": "=if(getMonth([$StartDate])=='','', [$StartDate.displayValue]+' - '+ [$EndDate.displayValue])",
      "attributes": {
        "class": "ms-fontColor-themePrimary"
      }
    },
    {
      "elmType": "div",
      "style": {
        "display": "flex",
        "justify-content": "space-between",
        "width": "100%",
        "padding-bottom": "5px",
        "margin-left": "-5px"
      },
      "attributes": {
        "class": "ms-fontColor-themePrimary ms-fontWeight-bold"
      },
      "children": [
        {
          "elmType": "span",
          "txtContent": "1"
        },
        {
          "elmType": "span",
          "txtContent": "5"
        },
        {
          "elmType": "span",
          "txtContent": "10"
        },
        {
          "elmType": "span",
          "txtContent": "15"
        },
        {
          "elmType": "span",
          "txtContent": "20"
        },
        {
          "elmType": "span",
          "txtContent": "25"
        },
        {
          "elmType": "span",
          "txtContent": "30"
        }
      ]
    },
    {
      "elmType": "div",
      "style": {
        "width": "100%",
        "border": "2px solid",
        "height": "30px",
        "fill": "currentColor"
      },
      "attributes": {
        "class": "ms-fontColor-themePrimary"
      },
      "children": [
        {
          "elmType": "svg",
          "style": {
            "width": "100%",
            "height": "100%",
            "display": "=if([$EndDate]>=[$StartDate],'','none')"
          },
          "children": [
            {
              "elmType": "path",
              "attributes": {
                "d": "= 'M ' + ((Number(Date([$StartDate]))/1000/60/60/24)-(Number(Date(''+ (getMonth([$StartDate]) + 1) + '/1/' + getYear([$StartDate]) ))/1000/60/60/24))*6.452 + ',0  ' + ((Number(Date([$EndDate]))/1000/60/60/24)-(Number(Date(''+ (getMonth([$StartDate]) + 1) + '/1/' + getYear([$StartDate]) ))/1000/60/60/24)+1)*6.452 + ',0 ' + ((Number(Date([$EndDate]))/1000/60/60/24)-(Number(Date(''+ (getMonth([$StartDate]) + 1) + '/1/' + getYear([$StartDate]) ))/1000/60/60/24)+1)*6.452 + ',40 ' + ((Number(Date([$StartDate]))/1000/60/60/24)-(Number(Date(''+ (getMonth([$StartDate]) + 1) + '/1/' + getYear([$StartDate]) ))/1000/60/60/24))*6.452 + ', 40 Z'"
              }
            }
          ]
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates the display of a monthly Gantt chart. The Gantt chart for the month corresponding to the StartDate value will be shown. For example, if the StartDate is March 15, the Gantt chart for March will be displayed; if the StartDate is April 2, the Gantt chart for April will be shown.

screenshot of the sample

View requirements

This format can be applied to any column type but expects the following columns to be part of the view:

Type Internal Name Required
Date and Time StartDate Yes
Date and Time EndDate Yes

Sample

Solution Author(s)
generic-monthly-gantt-chart.json Ahmed Mandour

Version history

Version Date Comments
1.0 February 16, 2025 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Additional notes

  • This sample uses SVG to display the Gantt chart. The generic-time-schedule displays a time-based schedule using the same approach.