How to Integrate Gantt Chart Light Library in Your JavaScript Stack
Overview
A concise guide to add a lightweight Gantt chart component to a modern JavaScript app (vanilla, React, Vue, or Svelte). Assumes the library is distributed as an ES module and offers a small CSS file plus an API to create charts, add tasks, and respond to events.
1. Install
- npm:
npm install gantt-chart-light - yarn:
yarn add gantt-chart-light - or include via CDN: “ and link CSS.
2. Basic usage (vanilla JS)
html
<link rel=”stylesheet“ href=”nodemodules/gantt-chart-light/dist/gantt-chart-light.css“> <div id=”gantt“></div> <script type=”module“> import { Gantt } from ‘gantt-chart-light’; const gantt = new Gantt(document.getElementById(‘gantt’), { start: ‘2026-03-01’, end: ‘2026-04-01’, view: ‘weeks’ }); gantt.loadTasks([ { id: 1, name: ‘Design’, start: ‘2026-03-02’, end: ‘2026-03-10’, progress: 50 }, { id: 2, name: ‘Develop’, start: ‘2026-03-11’, end: ‘2026-03-25’, depends: [1] } ]); </script>
3. React integration
- Install and wrap in a component that mounts the chart once.
jsx
import React, { useRef, useEffect } from ‘react’; import { Gantt } from ‘gantt-chart-light’; import ‘gantt-chart-light/dist/gantt-chart-light.css’; export default function GanttChart({ tasks, options }) { const ref = useRef(null); useEffect(() => { const gantt = new Gantt(ref.current, options); gantt.loadTasks(tasks); return () => gantt.destroy(); }, [tasks, options]); return <div ref={ref} />; }
- Keep tasks stable (useMemo) to avoid unnecessary re-renders. Use event handlers from the library to sync edits back to state.
4. Vue integration
- Mount in mounted() hook and destroy in beforeUnmount(). Use v-bind to pass props and emit events on task changes.
js
import { Gantt } from ‘gantt-chart-light’; export default { props: [‘tasks’,‘options’], mounted() { this.gantt = new Gantt(this.\(el</span><span class="token" style="color: rgb(57, 58, 52);">,</span><span> </span><span class="token" style="color: rgb(0, 0, 255);">this</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span>options</span><span class="token" style="color: rgb(57, 58, 52);">)</span><span class="token" style="color: rgb(57, 58, 52);">;</span><span> </span><span> </span><span class="token" style="color: rgb(0, 0, 255);">this</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span>gantt</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span class="token" style="color: rgb(57, 58, 52);">loadTasks</span><span class="token" style="color: rgb(57, 58, 52);">(</span><span class="token" style="color: rgb(0, 0, 255);">this</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span>tasks</span><span class="token" style="color: rgb(57, 58, 52);">)</span><span class="token" style="color: rgb(57, 58, 52);">;</span><span> </span><span> </span><span class="token" style="color: rgb(0, 0, 255);">this</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span>gantt</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span class="token" style="color: rgb(57, 58, 52);">on</span><span class="token" style="color: rgb(57, 58, 52);">(</span><span class="token" style="color: rgb(163, 21, 21);">'taskChange'</span><span class="token" style="color: rgb(57, 58, 52);">,</span><span> </span><span class="token parameter">task</span><span> </span><span class="token" style="color: rgb(57, 58, 52);">=></span><span> </span><span class="token" style="color: rgb(0, 0, 255);">this</span><span class="token" style="color: rgb(57, 58, 52);">.</span><span class="token" style="color: rgb(57, 58, 52);">\)emit(‘update:task’, task)); }, beforeUnmount() { this.gantt.destroy(); } }
5. Svelte integration
- Initialize in onMount, use store or props for tasks, and cleanup on destroy. Bind events to dispatch updates.
6. Styling & themes
- Override CSS variables or import a theme file if provided. Prefer class-based overrides for safe upgrades.
- Use container size and responsive options to let the chart adapt; set max-height with overflow for large charts.
7. Data model & syncing
- Use a normalized tasks array: id, name, start, end/duration, progress, depends, assignee, custom fields.
- On in-chart edits, listen to events (taskAdd, taskChange, taskDelete) and update your app state and backend via REST/GraphQL.
- Debounce bulk syncs and send diffs instead of full arrays for performance.
8. Performance tips
- Virtualize long task lists in the grid if supported.
- Use incremental updates (add/update/delete) rather than reloading all tasks.
- Limit DOM-heavy features (complex templates, many custom element nodes).
- Lazy-load heavy dependencies and charts for offscreen routes.
9. Accessibility & keyboard
- Ensure role and aria attributes are present or add them in a wrapper.
- Provide keyboard navigation, focus outlines, and high-contrast theme options.
Leave a Reply