Annotations

Annotations overlay vertical markers and shaded regions on the timeline. Use them to call out deadlines, sprints, milestones, holidays, or any point or range in time that the viewer should notice.

Point annotation

A point annotation draws a vertical line at a single date. Set x1 to the date and omit x2:

const gantt = new ApexGantt(document.getElementById('chart'), {
  series: tasks,
  annotations: [
    {
      x1: '2024-04-01',
      label: { text: 'Go-live' },
    },
  ],
})

Range annotation

Set both x1 and x2 to shade a region between two dates:

const gantt = new ApexGantt(el, {
  series: tasks,
  annotations: [
    {
      x1: '2024-03-01',
      x2: '2024-03-15',
      label: { text: 'Sprint 1' },
    },
    {
      x1: '2024-03-18',
      x2: '2024-03-29',
      label: { text: 'Sprint 2' },
    },
  ],
})

Annotation interface

PropertyTypeDefaultDescription
x1stringRequiredStart date (ISO 8601 or any format ApexGantt parses)
x2string | nullEnd date. When set, a shaded region is drawn between x1 and x2.
bgColorstringannotationBgColorBackground fill for this annotation (overrides the global default)
borderColorstringannotationBorderColorBorder / line color for this annotation
borderDashArraynumber0SVG stroke-dasharray value
borderWidthnumberannotationBorderWidthBorder line width in pixels
labelAnnotationLabelOptional label drawn at the annotation

Label styling

PropertyTypeDescription
textstringThe label text
fontColorstringText color
fontFamilystringFont family
fontSizestringFont size (e.g. '12px')
fontWeightstringFont weight (e.g. '600')
orientation'horizontal' | 'vertical'Label orientation; horizontal is default
const gantt = new ApexGantt(el, {
  series: tasks,
  annotations: [
    {
      x1: '2024-06-15',
      borderColor: '#EF4444',
      borderWidth: 2,
      label: {
        text: 'Deadline',
        fontColor: '#EF4444',
        fontWeight: '700',
        fontSize: '12px',
      },
    },
  ],
})

Global annotation defaults

Set defaults for all annotations at once using top-level options. Per-annotation properties override these when present:

OptionTypeDefaultDescription
annotationBgColorstring'#F9D1FC'Background color for all range annotations
annotationBorderColorstring'#E273EA'Border/line color for all annotations
annotationBorderDashArraynumber[][]SVG stroke-dasharray for all annotation borders
annotationBorderWidthnumber2Border width in pixels
annotationOrientation'horizontal' | 'vertical''horizontal'Orientation of all annotation labels
const gantt = new ApexGantt(el, {
  series: tasks,
  annotationBgColor: '#DBEAFE',
  annotationBorderColor: '#3B82F6',
  annotationBorderWidth: 1,
  annotations: [
    { x1: '2024-03-01', x2: '2024-03-15', label: { text: 'Sprint 1' } },
    { x1: '2024-03-18', x2: '2024-03-29', label: { text: 'Sprint 2' } },
    // these inherit the global blue styling
  ],
})

Mixed styles

Combine global defaults with per-annotation overrides to create visual variety:

const gantt = new ApexGantt(el, {
  series: tasks,
  annotationBgColor: '#DBEAFE',
  annotationBorderColor: '#3B82F6',
  annotations: [
    // inherits global blue
    { x1: '2024-03-01', x2: '2024-03-15', label: { text: 'Sprint 1' } },
    // red for a deadline
    {
      x1: '2024-04-01',
      borderColor: '#EF4444',
      bgColor: '#FEE2E2',
      label: { text: 'Deadline', fontColor: '#EF4444' },
    },
  ],
})

Updating annotations at runtime

Call update() to replace the annotations array after mount:

gantt.update({
  annotations: [
    { x1: '2024-05-01', label: { text: 'Phase 2 start' } },
    { x1: '2024-05-01', x2: '2024-05-31', label: { text: 'May Sprint' } },
  ],
})

update() does a shallow merge with the existing options, so only the keys you pass are replaced.

Project boundary lines

enableProjectBoundary: true draws two automatic vertical lines: one at the earliest task start and one at the latest task end. The lines update automatically as tasks are added, removed, or rescheduled.

const gantt = new ApexGantt(el, {
  series: tasks,
  enableProjectBoundary: true,
  projectBoundaryColor: '#7C3AED',   // default: '#7C3AED'
})

The boundary lines respond to runtime mutations (addTask, deleteTask, drag, resize) without needing a manual update() call.

React example

import { useState } from 'react'
import { ApexGanttChart } from 'react-apexgantt'
import type { GanttUserOptions } from 'react-apexgantt'

const baseOptions: Omit<GanttUserOptions, 'series'> = {
  annotationBgColor: '#DBEAFE',
  annotationBorderColor: '#3B82F6',
  annotationBorderWidth: 1,
  enableProjectBoundary: true,
}

export default function AnnotatedGantt() {
  const [annotations, setAnnotations] = useState([
    { x1: '2024-03-01', x2: '2024-03-15', label: { text: 'Sprint 1' } },
    { x1: '2024-03-18', x2: '2024-03-29', label: { text: 'Sprint 2' } },
    {
      x1: '2024-04-01',
      borderColor: '#EF4444',
      bgColor: '#FEE2E2',
      label: { text: 'Go-live', fontColor: '#EF4444', fontWeight: '700' },
    },
  ])

  return (
    <ApexGanttChart
      tasks={tasks}
      options={{ ...baseOptions, annotations }}
      viewMode="week"
      height="500px"
    />
  )
}

Vue example

<template>
  <ApexGanttChart
    :tasks="tasks"
    :options="ganttOptions"
    view-mode="week"
    height="500px"
  />
</template>

<script setup lang="ts">
import type { GanttUserOptions } from 'vue-apexgantt'

const ganttOptions: Partial<GanttUserOptions> = {
  annotationBgColor: '#DBEAFE',
  annotationBorderColor: '#3B82F6',
  enableProjectBoundary: true,
  annotations: [
    { x1: '2024-03-01', x2: '2024-03-15', label: { text: 'Sprint 1' } },
    {
      x1: '2024-04-01',
      borderColor: '#EF4444',
      label: { text: 'Go-live', fontColor: '#EF4444' },
    },
  ],
}
</script>