Skip to content

rect

Draws a rectangle for each data item.

js
gf.Chart([{ value: 80 }])
  .mark(gf.rect({ w: 120, h: "value", fill: "steelblue", rx: 4 }))
  .render(root, { w: 200, h: 150 });

Signature

ts
rect({ w?, h?, fill?, stroke?, strokeWidth = 0, rx?, ry?, label? })

Parameters

OptionTypeDescription
wnumber | stringWidth — number for fixed, field name to encode data
hnumber | stringHeight — number for fixed, field name to encode data
fillstringFill color or field name for color encoding
strokestringStroke color (defaults to fill)
strokeWidthnumberStroke width
rxnumberHorizontal border radius
rynumberVertical border radius
labelbooleanRender field value as text label inside rect

Examples

ts
// Bar chart: height encodes "value" field
.mark(rect({ h: "value" }))

// Fixed size with rounded corners
.mark(rect({ w: 20, h: 20, rx: 4 }))

// Color encodes "category" field
.mark(rect({ h: "value", fill: "category" }))

// Named for use with select()
.mark(rect({ h: "value" }).name("bars"))