Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script type='text/javascript' src='https://code.highcharts.com/gantt/9.1.2/highcharts-gantt.js'></script>
<div id='milestone-chart'></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                (function (H) {
    H.Renderer.prototype.symbols.diamond = H.Renderer.prototype.symbols.triangle;
})(Highcharts);

var originalData = [
    {
        projectName: "Project 1 Main",
        milestones: [
            { Finish: "2019-07-31T08:00:00", Name: "Project 1 Main - PHS-B", Type: "PHS-B" },
            { Finish: "2022-09-30T08:00:00", Name: "Project 1 Main - PHS-C", Type: "PHS-C" },
            { Finish: "2024-09-03T08:00:00", Name: "Project 1 Main - PHS-D", Type: "PHS-D" },
            { Finish: "2027-02-10T08:00:00", Name: "Project 1 Main - PHS-E", Type: "PHS-E" },
            { Finish: "2020-08-12T08:00:00", Name: "Project 1 Main - AAR", Type: "AAR" },
            { Finish: "2022-08-15T08:00:00", Name: "Project 1 Main - BBR", Type: "BBR" },
            { Finish: "2023-08-09T08:00:00", Name: "Project 1 Main - CCR", Type: "CCR" },
            { Finish: "2025-09-05T08:00:00", Name: "Project 1 Main - DDR", Type: "DDR" },
            { Finish: "2026-09-08T08:00:00", Name: "Project 1 Main - EER", Type: "EER" },
            { Finish: "2027-06-15T08:00:00", Name: "Project 1 Main - FFR", Type: "FFR" }
        ]
    },
    {
        projectName: "SubProject 1",
        milestones: [
            { Finish: "2020-05-15T08:00:00", Name: "SubProject 1 AAR", Type: "AAR" },
            { Finish: "2022-05-04T08:00:00", Name: "SubProject 1 BBR", Type: "BBR" },
            { Finish: "2023-07-14T08:00:00", Name: "SubProject 1 CCR", Type: "CCR" },
            { Finish: "2024-09-03T08:00:00", Name: "SubProject 1 DDR", Type: "DDR" },
            { Finish: "2025-04-19T08:00:00", Name: "SubProject 1 Deliver XYZ to Project 1 Main", Type: "DEL" }
        ]
    },
    {
        projectName: "SubProject 2",
        milestones: [
            { Finish: "2020-05-07T08:00:00", Name: "SubProject 2 AAR", Type: "AAR" },
            { Finish: "2022-06-08T08:00:00", Name: "SubProject 2 BBR", Type: "BBR" },
            { Finish: "2023-06-12T08:00:00", Name: "SubProject 2 CCR", Type: "CCR" },
            { Finish: "2025-02-01T08:00:00", Name: "SubProject 2 DDR", Type: "DDR" },
            { Finish: "2025-04-26T08:00:00", Name: "SubProject 2 - Deliver LMNO to Project 1 Main", Type: "DEL" }
        ]
    },
    {
        projectName: "SubProject 3",
        milestones: [
            { Finish: "2020-05-07T08:00:00", Name: "SubProject 3 AAR Table Top Review", Type: "AAR" },
            { Finish: "2022-04-25T08:00:00", Name: "SubProject 3 BBR", Type: "BBR" },
            { Finish: "2023-08-08T08:00:00", Name: "SubProject 3 CCR", Type: "CCR" },
            { Finish: "2024-03-13T08:00:00", Name: "SubProject 3 DDR", Type: "DDR" },
            { Finish: "2024-02-26T08:00:00", Name: "SubProject 3 - JKL to Project 1 Main", Type: "DEL" },
            { Finish: "2024-10-01T08:00:00", Name: "SubProject 3 - ABCD to Project 1 Main", Type: "DEL" },
            { Finish: "2024-10-01T08:00:00", Name: "SubProject 3 - HIJK to Project 1 Main", Type: "DEL" }
        ]
    }
];

var lastPublishDate = new Date();

var yAxisCategories = [];
var allSeries = [];

var extraCopy = {
  projectName: `${originalData[0].projectName} Copy`,
  milestones: [...originalData[0].milestones]
}

originalData.push(extraCopy);

originalData.forEach((project, idx) => {
  yAxisCategories.push(project.projectName);
  generateSeriesData(project, lastPublishDate, idx, allSeries);
});
                     
var rowHeight = 80;
var newChartHeight = (originalData.length * rowHeight) + 231; // with all navigation options enabled, the "overhead" height outside the plot area is 231

Highcharts.ganttChart('milestone-chart', {
  chart: {
    events: {
      load: function () {
        window.myChart = this;
        this.series.forEach(series => {
          var offset = series.name.toLowerCase().includes('completion') ? 17 : 13
          series.points.forEach(point => {
            point.graphic.translate(0, offset)
          });
        });
        setInitialZoom(this, lastPublishDate)
      }
    },
    height: newChartHeight,
    zoomType: 'x'
  },
  navigator: {
    enabled: true,
    liveRedraw: true
  },
  scrollbar: {
    enabled: true,
    liveRedraw: true
  },
  rangeSelector: {
    enabled: true
  },
  plotOptions: {
    series: {
      states: {
        inactive: {
          opacity: 1
        }
      }
    }
  },
  yAxis: {
    type: 'category',
    categories: yAxisCategories,
    reversed: true
  },
  series: allSeries
})

function generateSeriesData(project, lastPublishDate, yValue, allSeries) {
  var completionSeriesData = [];
  var milestoneSeriesData = [];
  
  project.milestones.sort((a,b) => {
    aDate = new Date(a.Finish).getTime();
    bDate = new Date(b.Finish).getTime();
    return aDate - bDate;
  });

  var earliestMstn = new Date(project.milestones[0].Finish)
  var latestMstn =  new Date(project.milestones[project.milestones.length - 1].Finish)

  completionSeriesData.push({
    name: 'Complete',
    y: yValue,
    start: earliestMstn.getTime(),
    end: latestMstn < lastPublishDate ? latestMstn.getTime() : lastPublishDate.getTime(),
    opacity: 0.85
  })

  if (latestMstn > lastPublishDate) {
    completionSeriesData.push({
      name: 'Pending',
      y: yValue,
      start: lastPublishDate.getTime(),
      end: latestMstn.getTime(),
      opacity: 0.45
    })
  }
  
  project.milestones.forEach(mstn => {
    var finish = new Date(mstn.Finish);
    var point = {
      name: mstn.Name,
      y: yValue,
      milestone: true,
      start: finish.getTime(),
      end: finish.getTime(),
      mstnType: mstn.Type
    };
    if (finish > lastPublishDate) {
      point.opacity = 0.7;
    }
    milestoneSeriesData.push(point);
  });

  var completionSeries = {
    name: `${project.projectName} Completion`,
    data: completionSeriesData,
    groupPadding: 0.4,
    showInNavigator: true,
    tooltip: {
      headerFormat: '<span style="font-size: 10px">{point.yCategory}</span><br/>',
      pointFormatter: function () {
        return `<span><strong>${this.name}</strong></span><br/><span>${new Date(this.start).toLocaleDateString('en-US')} - ${new Date(this.end).toLocaleDateString('en-US')}</span>`;
      },
      followPointer: true
    }
  }

  var milestoneSeries = {
    name: `${project.projectName} Milestones`,
    data: milestoneSeriesData,
    groupPadding: 0.25,
    showInNavigator: true,
    dataLabels: {
      formatter: function () {
          var date = new Date(this.point.start);
          if (this.point.mstnType) {
            return `${this.point.mstnType}<br/>${date.getMonth() + 1}/${date.getDate()}`;
          } else {
            return `${date.getMonth() + 1}/${date.getDate()}`;
          }
        },
        inside: false,
        y: yValue === 0 ? 0 : -31
      },
      tooltip: {
        headerFormat: '<span style="font-size: 10px">{point.yCategory}</span><br/>',
        pointFormatter: function () {
          var options = { weekday: 'long', year: 'numeric', month: 'short', day: 'numeric' };
          return `<span><strong>${this.name}</strong></span><br/><span>${new Date(this.start).toLocaleDateString('en-US', options)}</span>`;
        }
      }
    }

    allSeries.push(completionSeries);
    allSeries.push(milestoneSeries);
}

function setInitialZoom (chart, lastPublishDate) {
    var lastMonth = new Date(lastPublishDate)
    lastMonth.setMonth(lastMonth.getMonth() - 1)
    lastMonth.setDate(1)
    var twoYears = new Date(lastPublishDate)
    twoYears.setMonth(twoYears.getMonth() + 24)
    twoYears.setDate(1)
    chart.xAxis[0].setExtremes(lastMonth.getTime(), twoYears.getTime(), true);
}
              
            
!
999px

Console