Skip to content

Gantt chart ​

Since 1.7.0

@maxgrid/gantt-core and @maxgrid/gantt (createGantt, createSplitView, attachGrid) are available since 1.7.0. Version 1.7.0 is read-only.

Concepts ​

The Gantt chart is a chart pane that sits next to the grid. It is read-only by default; since 1.8.0 editable: true lets users drag to change the schedule (Editing). The grid shows the task list, and the chart draws schedule bars and dependency arrows on the same rows.

  • Scheduling belongs to your server (a PMS). The module never recomputes dates. It draws the dates it receives.
  • There are two packages. @maxgrid/gantt-core is pure TypeScript with no DOM (data normalization, time scale, calendars, bar and arrow layout). @maxgrid/gantt is the chart pane, its CSS, and the grid sync.
  • It is not part of the maxgrid bundle. You load it separately where you need it, so the grid size does not change.
  • The Gantt is part of MaxGrid and needs no separate key; a key of the "MaxGrid + Gantt" product covers it. With a key of the grid-only product the Gantt runs in evaluation mode (watermark strip). Set the key the same way as for the grid, with MaxGrid.config({ licenseKey }) or the licenseKey option (License key).
  • You can also use the chart without a grid (Using the Gantt chart without the grid).
  • It is built with the framework-agnostic createGantt. There are no React, Vue, or Angular wrappers in 1.7.

Quick start ​

With ESM, create the grid, the chart, and a split view, then link them with attachGrid.

ts
import { createGrid } from 'maxgrid';
import { createGantt, createSplitView } from '@maxgrid/gantt';
import '@maxgrid/gantt/gantt.css';

const ROW_HEIGHT = 32;

const grid = createGrid(gridEl, {
  columns: [
    { id: 'wbsCode', title: 'WBS', width: 80 },
    { id: 'name', title: 'Task', width: 220 },
  ],
  rows: tasks,
  rowKey: 'id',
  headerHeight: 48, // must equal the Gantt header height
  rowHeight: ROW_HEIGHT, // must equal the Gantt rowHeight
});

const gantt = createGantt(ganttEl, { rowHeight: ROW_HEIGHT, locale: 'en' });
gantt.setData({ tasks, dependencies, calendars });

createSplitView({ left: gridEl, right: ganttEl, container: wrapEl, initial: 0.4 });
const unlink = gantt.attachGrid(grid);

With script tags, load maxgrid.gantt.min.js and maxgrid.gantt.css. The global name is MaxGridGantt.

html
<link rel="stylesheet" href="maxgrid.gantt.css" />
<script src="maxgrid.gantt.min.js"></script>
<script>
  const gantt = MaxGridGantt.createGantt(ganttEl, { rowHeight: 32 });
  gantt.setData(data);
  gantt.attachGrid(grid);
</script>

Set the grid headerHeight to 48 (GANTT_HEADER_HEIGHT) and its rowHeight to the same value as the chart. It is one grid option line.

ts
createGrid(el, { columns, rows, rowKey: 'id', headerHeight: 48, rowHeight: 32 }); // same rowHeight as the chart

The grid's default headerHeight is 36, so if you leave it the rows sit about 12 px off from the chart. A different rowHeight adds up row by row. attachGrid prints a console hint once when the values differ ([gantt] set the grid headerHeight to 48 …). The unified mode of createSplitView sets the card's header height to 48 but does not change the grid's options for you, so in unified mode too you pass headerHeight: 48 to the grid yourself.

Data format ​

setData takes a GanttData. Dates are YYYY-MM-DD strings and all ids are strings (so 64-bit ids never turn into lossy numbers).

ts
interface GanttData {
  tasks: GanttTask[];
  dependencies: GanttDependency[];
  calendars: GanttCalendar[];
}

Task (GanttTask) ​

FieldTypeDescription
idstringTask id
parentIdstring | nullParent task. null for top level
sortNonumberOrder inside the parent, ascending. The tree is flattened depth first
namestringTask name
status'TODO' | 'IN_PROGRESS' | 'DONE' | 'ON_HOLD' | 'CANCELED'Status
plannedStart, plannedEndstring | nullPlanned start and end (end is inclusive). null shows the row without a bar
progressPctnumberProgress, 0 to 100
isMilestonebooleanA milestone is drawn as a diamond on one day
hasChildrenbooleanSummary task. The server aggregates its dates and progress
calendarIdstring | nullCalendar. null means the default calendar
wbsCode, assigneeNamestring (optional)Shown in the tooltip
versionnumberConcurrency token owned by your server. The module only passes it through

Dependencies and calendars ​

TypeFields
GanttDependencyid, predecessorId, successorId, depType ('FS' | 'SS' | 'FF' | 'SF'), lagDays (working days, negative allowed)
GanttCalendarid, name, workDays (sum of Mon=1, Tue=2, Wed=4, Thu=8, Fri=16, Sat=32, Sun=64), hoursPerDay (optional), isDefault, exceptions
GanttCalendarExceptiondate, working, note (optional)

PMS source (snake_case) ​

If your server sends snake_case JSON, convert it with normalizePmsData from @maxgrid/gantt-core. Ids become strings.

ts
import { normalizePmsData } from '@maxgrid/gantt-core';

gantt.setData(normalizePmsData(await (await fetch('/api/gantt')).json()));

Options ​

GanttOptions, used by createGantt(container, options?) and setOptions(partial).

OptionTypeDefaultDescription
zoom'day' | 'week' | 'month''day'Zoom level
rowHeightnumber32Row height in px. Use 24 for a compact chart. Must equal the grid
locale'ko' | 'en' | 'ja''ko'Language of headers, tooltips, and accessible text
todaystringnowDate treated as today. For tests
showTodaybooleantrueVertical today line
showWeekendsbooleantrueWeekend and holiday shading
barHeightnumberhalf of rowHeight, roundedBar height
ariaLabelstring-aria-label of the chart region
collapsedstring[]-Task ids collapsed from the start
licenseKeystring-MaxGrid license key. The global key is used when not set
editableboolean | GanttEditablefalseDrag to change the schedule. An object switches move, resize, progress, link and reorder one by one (1.8.0, Editing)
resetScrollOnDatabooleanfalseReturn to the start position on every setData. By default only the first call does
verticalScroll'own' | 'external''own''external': one host scroller owns the vertical scroll (1.7.2). Set at creation; setOptions cannot change it

API ​

NameDescription
createGantt(container, options?)Creates the chart and returns a GanttApi
createSplitView({ left, right, container, initial?, min?, ... })Creates a draggable split between two areas. initial is px or a 0 to 1 ratio. Returns { destroy, setSize(n), getSize(), setCollapsed(bool), isCollapsed(), unified }. The other options are under "Split view and one scroller" below

Members of GanttApi.

GroupMembers
DatasetData(data), setOptions(partial)
Zoom and movesetZoom(z), getZoom(), scrollToDate(date, align?), scrollToToday(), fitToProject()
Selection and rowsselectRow(id | null), getSelectedRow(), scrollToRow(id), getVisibleRows(), setRowOrder(ids | null)
Collapsecollapse(id), expand(id), collapseAll(), expandAll(), isCollapsed(id)
ScrollgetScrollTop(), setScrollTop(top), getScrollLeft(), setScrollLeft(left), onScrollY(fn), getRowHeight()
LinkattachGrid(grid, { rowKey?, gridElement?, unified? })
Events and cleanupon(name, fn) (returns an unsubscribe function), destroy()
From 1.8applyPatch(patch), revertIntent(intentId). They do nothing in 1.7

The pure functions in @maxgrid/gantt-core work without a DOM, so you can use them on a server or in tests.

FunctionWhat it does
parseDay(s), formatDay(n)Convert between YYYY-MM-DD and a day number (days since 1970-01-01)
normalizePmsData(raw)Turns PMS snake_case JSON into GanttData
buildRows(tasks, collapsed)Flattens the tree depth first, honoring collapsed tasks
createTimeScale(opts)Date to x conversion and header cells
createCalendarIndex(calendars)isWorking, nonWorkingRanges, workingDays
layoutBars(rows, scale, opts)Bar rectangles for a window of visible rows
routeArrows(deps, barIndex, opts)Orthogonal routes for dependency arrows
makeFixture(opts)Deterministic sample data for performance tests (5,000 tasks and more)

Events ​

Subscribe with gantt.on(name, fn). Call the returned function to unsubscribe.

EventValueWhen
row-select{ taskId }A row or bar is clicked. null when the selection is cleared
toggle-collapse{ taskId, collapsed }A task is collapsed or expanded
task-open{ taskId }A bar or row is double-clicked
viewport-change{ zoom, from, to }The zoom changes or scrolling settles (100 ms debounce)
ts
const off = gantt.on('task-open', ({ taskId }) => openDetail(taskId));
off();

The chart has no collapse chevrons. The grid or the API owns collapsing. The move, resize, progress, and dependency events (task-move, task-resize, task-progress, dependency-create, dependency-delete) are coming in 1.8, and task-reorder in 1.9.

Split view and one scroller ​

How the grid and chart scroll as one block is in Grid and chart in one scroll and External vertical scroll.

createSplitView divides the left side (grid) and the right side (chart) with a divider. Drag it or move it with the arrow keys; a double click restores the start size.

OptionDefaultDescription
initial0.4Start width of the grid side, in px or as a ratio between 0 and 1
min160Minimum width of each side (px)
unifiedautomaticOne vertical scroller for both sides (1.7.2). On when the left grid is created with verticalScroll: 'external', otherwise off. false forces the two-scroller layout, true forces the unified one
collapseButtontrueA round button on the divider that collapses the grid to 0 and restores it (1.8.0). setCollapsed and isCollapsed do the same from code
narrowBelow600 unified, 0 (off) otherwiseWhen the container is narrower than this (px), the grid starts at narrowInitial of the width so the chart keeps room. Once you move the divider it no longer follows
narrowInitial0.38Ratio of the grid side when narrow
label, groupLabel, localetext for the languageAccessible names of the divider and of the unified card (role="group")

To merge the scrollers, create both the grid and the chart with verticalScroll: 'external'. There is then a single vertical scrollbar and the grid and chart rows line up to 0 px. The evaluation strip also shows once, on the card.

ts
const grid = createGrid(gridEl, {
  columns,
  rows,
  rowKey: 'id',
  rowHeight: 32,
  headerHeight: 48,
  verticalScroll: 'external',
});
const gantt = createGantt(ganttEl, { rowHeight: 32, verticalScroll: 'external' });
gantt.setData(data);
const split = createSplitView({ left: gridEl, right: ganttEl, container: wrapEl });
const unlink = gantt.attachGrid(grid, { unified: true });
  • With 'external', row n sits at n × rowHeight, so options that change row height (autoGridHeight, rowHeight: 'auto' or a function, rowsResizable, detail, bodyLayout) cannot be combined with it. Option validation rejects them.
  • To build the scroller yourself, pass the host scroller's scrollTop to both grid.external.setViewport({ scrollTop }) and gantt.external.setViewport({ scrollTop }), and listen to both sides' onRequest for scroll requests. spacerHeight() gives the height the scroller needs; toVirtual and toDom convert positions for very long lists (millions of rows are scrolled in a shorter height).
  • The grid's top and bottom pinned areas (pinnedRows) have no matching rows in the chart, so rows drift apart. Pin rows inside the data instead.

Grid sync ​

Since 1.7.2

When the grid and the chart are created with verticalScroll: 'external' and placed in createSplitView, they work as one block of scroll. Up to 1.7.1 the two scroll areas were kept in step, and that path is still there.

There are two ways to place the grid and the chart side by side. When both use verticalScroll: 'external' you get unified scroll. Otherwise (the unchanged default, a grid from another library, unified: false) it is the two-scroller path (the old way). Setup and rules of unified scroll are in Grid and chart in one scroll; the grid option and API are in External vertical scroll.

Unified scroll (when both are external) ​

ts
const grid = createGrid(gridEl, {
  columns,
  rows,
  rowKey: 'id',
  rowHeight: 32,
  verticalScroll: 'external',
});
const gantt = createGantt(ganttEl, { rowHeight: 32, verticalScroll: 'external' });
createSplitView({ left: gridEl, right: ganttEl, container: wrapEl, initial: 0.4 });
gantt.attachGrid(grid);
  • One vertical scrollbar, at the far right. Wheel, touch pan and keyboard scrolling over the grid or over the chart move the same scroll area, so both sides go up and down as one block. There is no code that syncs them, so they cannot drift apart.
  • Headers stay put. Only the rows scroll; the grid header and the chart header stay at the top.
  • Each pane has its own horizontal scrollbar at its bottom. Pushing the grid sideways (many columns) leaves the chart still, and pushing the chart sideways leaves the grid still. Date moves such as scrollToToday change only the chart's horizontal position.
  • Rows line up exactly. Both panes draw the same row range for the same scroll value, so row n has the same top and bottom on both sides (checked at 0 px difference at screen scales 100%, 125%, 150% and 200%). To keep this, every row must have the same height: give both sides the same integer rowHeight (px) and the same header height (rowHeight: 'auto' or a function, rowsResizable, detail, bodyLayout and autoGridHeight cannot be combined with it). If they differ it calls console.warn once.
  • Very many rows work. At one million rows the grid and the chart share the rule that compresses the scroll height, so the last row is reachable.
  • The grid's getScroll() returns the last value the unified scroll area gave, and grid actions such as scrollToRow, ensureVisible and Ctrl+End ask the scroll area to change its position. The scroll area itself is not a tab stop. Keyboard movement in the grid and the chart is unchanged.

For theme authors: inside the .mxg-split-unified card, the vertical scroll area is .mxg-su-scroller. Its .mxg-su-spacer makes the full height and .mxg-su-sticky stays on screen and holds the left pane, the divider (.mxg-split-divider) and the right pane. In unified scroll the grid has the class mxg-external and the chart mxg-gantt-external. The card draws the outer border, so the grid's own border is removed.

To turn unified scroll off, use createSplitView({ ..., unified: false }) and attachGrid(grid, { unified: false }).

Two-scroller path (default, foreign grids, unified: false) ​

Without verticalScroll: 'external', with a grid that is not MaxGrid, or with unified: false, the grid and the chart keep their own scroll areas and are kept in step as before. In a split view there is one vertical scrollbar, on the chart (far right), and the grid's vertical scrollbar is hidden. Vertical wheel and touch input on the grid goes to the chart. To name the grid element yourself, pass attachGrid(grid, { gridElement }); gridElement: null leaves the grid's vertical scrollbar as it is. On screens with a horizontal scrollbar both sides still reach the end on the same row. Because two areas are drawn separately, this path does not promise the exact line match of unified scroll.

gridElement is used on this path only.

What both paths keep in sync ​

  • Row selection: selecting a grid row selects the chart row, and clicking in the chart selects the grid row.
  • Tree collapse: collapsing or expanding the grid tree calls the chart collapse and expand. The grid owns collapse. If you call gantt.collapse(id) through the API, the grid tree changes too.
  • Displayed rows (filter, sort, grouping, hidden rows, paging): the chart lines follow the lines the grid shows. A row the filter hides leaves the chart too, sorting reorders the bars, and lines that are not tasks (group headers, totals, "load more") keep their place as blank lines without a bar. The grid owns collapse then, and the chart's own collapse state is not used. An arrow to a hidden task attaches to its nearest shown ancestor, and is not drawn when no ancestor is shown. To drive it yourself call gantt.setRowOrder(ids) (null for a line that is not a task; setRowOrder(null) goes back to the collapse-aware tree).
  • Height check: if the grid rowHeight or headerHeight differs from the chart, it calls console.warn once.

Task ids are strings and grid row keys can be numbers, so both are compared as strings. If the grid rowKey is a different column from the task id, pass the property name that holds the task id in the rowKey option (default 'id').

The returned function unlinks them. Call it before destroy().

ts
const unlink = gantt.attachGrid(grid, { rowKey: 'taskId' });
unlink();

Zoom and calendars ​

Each zoom level has its own day width and two header tiers.

zoomDay widthCellTop tierBottom tier
day32pxone day2026-11short weekday and day (Mon 23)
week9pxISO week2026-11W47
month3pxone month202611월 (ko), Nov (en), 11月 (ja)

Everything works in whole days. fitToProject() fits the whole schedule on screen, and scrollToToday() jumps to the today line.

Pass calendars in calendars. The non-working days of the default calendar (isDefault: true), meaning weekends and the holidays in exceptions, are shaded over the body (turn it off with showWeekends). The tooltip shows the task name, WBS, assignee, dates, working days (by the task calendar), progress, and status. It appears 150 ms after the pointer rests on a bar and stays hidden while you scroll.

Theming ​

Colors are set only through CSS variables. The chart uses --mxg-gantt-*, then the grid theme --mxg-* value, then a built-in light or dark default. Set the variables on an ancestor or on .mxg-gantt-root.

css
.my-gantt {
  --mxg-gantt-today: #d92d20;
  --mxg-gantt-bar: #a9c2ee;
  --mxg-gantt-bar-progress: #1a56c4;
}
VariableUsed for
surface, stripe, grid-line, text, mutedBackground, striped rows, grid lines, text, secondary text
header-bg, header-text, header-heightHeader
selected, focusSelected row, focus
bar, bar-progressTo do and in progress bar fill and progress fill
bar-done, bar-done-progress, done-textDone
bar-hold, bar-hold-progress, hold-textOn hold
bar-cancel, bar-cancel-progress, cancel-textCanceled
overdue, overdue-textOverdue (planned end before today, progress under 100%, not done or canceled)
summary, milestoneSummary bracket, milestone
todayToday line
weekend, holidayWeekend and holiday shading
arrow, arrow-hoverDependency arrows

Prefix every name with --mxg-gantt-. Bars get a status class: mxg-gantt-bar--todo, --in_progress, --done, --on_hold, or --canceled. For dark mode, put data-mxg-theme="dark" on the root or an ancestor, the same switch the grid uses. Set it on <html> together with your app's own theme attribute and the grid, the chart, the tooltip and the unified split card all follow (Turn on dark mode).

Limits ​

  • It is read-only by default. Without editable: true you cannot drag or resize bars, and the cursor stays the default. Editing, row order and keyboard operation are in Editing; baseline and critical path are in Baseline and critical path (1.8.0).
  • It does not schedule. Your server decides dates and summary aggregation.
  • Picking and editing bars with the keyboard is described in Editing.
  • Fixed rows outside the grid data (pinnedRows.top and bottom) and the inner height of detail panels are not matched to chart lines. With such rows the lines drift apart; use pinning inside the data (pinRow) instead.
  • The target is 5,000 rows. Only the visible window is drawn, so scrolling stays smooth at that size.
  • There are no React, Vue, or Angular wrappers.
  • Right-to-left layouts are not supported yet.

Accessibility ​

  • The chart region has role="region". Name it with the ariaLabel option.
  • Each bar has role="img" and an aria-label like Task name, start - end, progress% (a milestone uses Task name, date), written in the locale language.
  • Selecting a row is done by mouse click. In 1.7, rows and bars do not take keyboard focus. To pick a task with the keyboard, select it in the grid and attachGrid follows with the chart selection.