Skip to contents

Draw a timeline (Gantt) chart: one horizontal bar per task, positioned by start and end on a value or time x-axis and grouped into rows by label on the y-axis. Implemented as an ECharts custom series (ECharts has no native Gantt series).

Usage

draw_gantt(
  tasks,
  group = NULL,
  axis_type = "value",
  bar_height = 0.6,
  bar_radius = 0,
  guides = TRUE,
  zoom = TRUE,
  tooltip = NULL,
  border = NULL,
  border_color = "#E53935",
  border_width = 1.5,
  xlab = NULL,
  title = NULL,
  palette = NULL,
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL,
  filename = NULL,
  legend_position = "top",
  legend_placement = "outside"
)

Arguments

tasks

Tabular data (data.frame, data.table, or tibble): One row per task bar. Must contain columns label (row / category), start, and end. Repeated label values place multiple bars on the same row.

group

Optional Character: Name of a column in tasks whose values color the bars and produce a legend. When NULL, all bars share one color.

axis_type

Character {"value", "time"}: Type of the x-axis. Use "value" for numeric offsets (e.g. milliseconds from start) and "time" for absolute timestamps; POSIXct/Date start/end columns are converted to epoch milliseconds automatically.

bar_height

Numeric (0, 1]: Bar thickness as a fraction of one category band.

bar_radius

Numeric [0, Inf): Bar corner radius in pixels.

guides

Logical: If TRUE, show an interactive axis pointer – a guide line that follows the mouse and labels the time value on the x-axis.

zoom

Logical: If TRUE, enable interactive zoom – mouse-wheel to zoom and drag to pan on both the time and row axes (inside dataZoom), plus a top-right toolbox with box-zoom, undo, and reset controls.

tooltip

Optional Character: Name of a column in tasks to show as the tooltip text for each bar. When NULL, a default label: start - end tooltip is shown.

border

Optional Character: Name of a logical column in tasks; bars whose value is TRUE get an outline (in border_color) without changing their fill – e.g. to flag failures while the fill still encodes the group.

border_color

Character: Outline color for bars flagged by border.

border_width

Numeric [0, Inf): Outline width in pixels.

xlab

Optional Character: x-axis label.

title

Optional Character: Chart title.

palette

Optional Character: Color palette as a single color or character vector overriding the theme palette. Groups are colored in order.

theme

Optional Theme: Theme override.

width

Optional Character or Numeric: Widget width.

height

Optional Character or Numeric: Widget height.

element_id

Optional Character: Explicit DOM element ID for the widget container. NULL lets htmlwidgets generate one.

filename

Optional Character: If provided, save the widget to this file via save_drawing().

legend_position

Character {"top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"}: Legend anchor. Top/bottom anchors use horizontal rows; left/right anchors use a vertical column. Corner anchors align within the top or bottom row.

legend_placement

Character {"outside", "inside"}: Relation to the plotting area. Outside placement reserves space for the complete legend; inside placement overlays the data. Neither setting adds a missing legend.

Value

htmlwidget: Widget object.

Details

The legend uses the shared position/placement controls and reserves enough room for the time axis. Tick density follows the available plotting width, and long task labels are truncated. Default bar tooltips retain the full task text. Browser resizing, panel figures, and SVG export share this layout behavior. Increase height when a timeline contains many task rows.

Author

EDG

Examples

tasks <- data.frame(
  label = c("load", "clean", "train", "predict"),
  start = c(0, 12, 30, 95),
  end = c(12, 30, 95, 100),
  status = c("ok", "ok", "ok", "error")
)
draw_gantt(tasks, group = "status")