Skip to content

Legend ​

The legend lives at legend on chartData. It controls series colors (legend.colors), visibility, typography, item order, and placement (docked slots or free-floating).

js
legend: {
  visible: true,
  position: 'rightTop', // docked slot, or 'free'
  orientation: 'vertical', // item flow: 'vertical' | 'horizontal'
  reverseOrder: false,
  colors: ['#4285F4', '#DB4437', '#F4B400'],
  itemVisibility: {},
  text: {
    fontSize: 11,
    fontColor: 'black',
    fontFamily: 'Arial',
  },
  // When position is 'free' only:
  // x: 0.55,
  // y: 0.08,
}

legend.orientation is item layout (stack vs row). It is not orientation on the chart (axes / bars). Flipping the chart does not flip the legend.


Placement model ​

Two modes, both via legend.position:

ModepositionPlot spaceCoordinates
DockedOne of 12 slots belowReserves margin (width on left/right, height on top/bottom)Engine places the legend; x / y are rewritten on draw — do not treat them as source of truth
Free-floating'free'Does not reserve margin (overlays the plot)x / y are fractions of the drawable chart area (roughly 0–1)

There is no separate dock / placement field.

Docked positions (12) ​

Side first, then alignment:

SideValues
ToptopLeft, topCenter, topRight
BottombottomLeft, bottomCenter, bottomRight
LeftleftTop, leftCenter, leftBottom
RightrightTop, rightCenter, rightBottom

Default is rightTop.

js
// Bottom strip
legend: {
  visible: true,
  position: 'bottomCenter',
  orientation: 'horizontal',
}

// Left rail
legend: {
  visible: true,
  position: 'leftTop',
  orientation: 'vertical',
}

Free-floating ​

js
legend: {
  visible: true,
  position: 'free',
  orientation: 'horizontal', // author-controlled; not tied to a dock
  x: 0.55,
  y: 0.08,
}

Precise x / y are easiest to set by dragging in edit mode, then exporting config. Free legends can overlap series or labels because they do not push the plot.


Orientation (item flow) ​

ValueLayout
verticalItems stack top → bottom (default; fits left/right docks)
horizontalItems flow sideways, may wrap (fits top/bottom docks)

When you drag the legend onto a dock in the editor, orientation is updated automatically:

Dock familyForced orientation
top* / bottom*horizontal
left* / right*vertical
freeunchanged

Hand-authored / API patches that only change position do not auto-update orientation. Always set a matching orientation when docking by config — e.g. bottomCenter + leftover vertical yields a tall legend on the bottom strip.


Visibility and items ​

FieldRole
visibleWhole legend on/off
itemVisibilityPer-series map: { "0": false } hides series 0 from the legend. Missing key or true = shown
reverseOrdertrue reverses series order in the legend

Defaults: legend starts hidden on waterfall, bar mekko, and pie/donut; shown on other types. Single-series charts often look cleaner with visible: false.

Hiding the last visible legend item also turns the whole legend off. Showing the legend again when every item was hidden clears itemVisibility.


Colors and text ​

FieldRole
colorsSeries / category fill palette (shared with the chart)
text.fontSize / fontFamily / fontColorLegend label typography

See also Colors & fonts.


Field reference ​

FieldTypeDefaultNotes
visiblebooleantype-dependentSee above
positionstring'rightTop'12 docks or 'free'
orientation'vertical' | 'horizontal''vertical'Item flow; match dock family when hand-authoring
x / ynumber0.13 / 0.05Used when position === 'free'
reverseOrderbooleanfalse
colorsstring[]org paletteSeries fills
itemVisibilityobject{}Keys are series index strings
text.fontSizenumber11pt
text.fontColorstring'black'
text.fontFamilystringorg default

Tips ​

  • Docked legends reserve plot space; free legends overlay it.
  • On horizontal charts, left/right docks compete with category labels for width — bottom or free often works better, or hide the legend.
  • Prefer edit-mode drag + exportConfig() / getChartData() when you need exact free placement or a precise dock alignment.

Developer documentation for Chartbuddy Embed · Not the end-user Help Center · Help Center