Toolforge Docs
DocsBlock OutputsareaChart

areaChart

Create area charts to visualize trends over time with filled areas under the lines.

Usage

Area chart

const chart = block.areaChart({
  title: 'Monthly Revenue',
  data: [
    { month: 'Jan', revenue: 4000, expenses: 2400 },
    { month: 'Feb', revenue: 3000, expenses: 1398 },
    { month: 'Mar', revenue: 2000, expenses: 9800 },
  ],
  index: 'month',
  categories: ['revenue', 'expenses'],
})

Props

PropDescriptionTypeRequiredDefault
titleChart title displayed above the chartstringNoundefined
descriptionDescription text below the titlestringNoundefined
dataArray of data objects to visualizeT[]Yes
indexKey of the data object for the x-axiskeyof TYes
categoriesKeys of the data object for the y-axis series(keyof T)[]Yes
colorsColors for each category seriesChartColor[]No['blue']
xAxisLabelLabel for the x-axisstringNoundefined
yAxisLabelLabel for the y-axisstringNoundefined
fillTypeType of fill under the area'gradient' | 'solid' | 'none'No'gradient'
stackTypeHow series are stacked'default' | 'stacked' | 'percent'No'default'
intervalTypeX-axis tick placement logic'equidistantPreserveStart' | 'preserveStartEnd'No'equidistantPreserveStart'
startEndOnlyShow only start and end labels on x-axisbooleanNofalse
showXAxisWhether to display the x-axisbooleanNotrue
showYAxisWhether to display the y-axisbooleanNotrue
showGridLinesWhether to display grid linesbooleanNotrue
showTooltipWhether to display tooltips on hoverbooleanNotrue
showLegendWhether to display the legendbooleanNotrue
valueFormatFormat configuration for valuesValueFormatNoundefined

Returns

Returns an AreaChartOutput object that can be returned from a handler or passed to io.message().

Examples

Basic area chart

Basic area chart

return block.areaChart({
  title: 'Website Traffic',
  data: trafficData,
  index: 'date',
  categories: ['visitors'],
  colors: ['blue'],
})

Stacked area chart

Stacked area chart

return block.areaChart({
  title: 'Revenue by Product',
  data: revenueData,
  index: 'month',
  categories: ['productA', 'productB', 'productC'],
  colors: ['blue', 'emerald', 'amber'],
  stackType: 'stacked',
})

Percentage stacked chart

Percentage stacked area chart

return block.areaChart({
  title: 'Market Share',
  data: marketData,
  index: 'quarter',
  categories: ['companyA', 'companyB', 'companyC'],
  stackType: 'percent',
  valueFormat: { type: 'percentage' },
})

With axis labels and formatting

With axis labels and formatting

return block.areaChart({
  title: 'Sales Performance',
  description: 'Monthly sales data for 2024',
  data: salesData,
  index: 'month',
  categories: ['sales'],
  xAxisLabel: 'Month',
  yAxisLabel: 'Revenue',
  valueFormat: {
    type: 'currency',
    currency: 'USD',
    notation: 'compact',
  },
})

Minimal chart without axes

Minimal chart without axes

return block.areaChart({
  data: sparkData,
  index: 'time',
  categories: ['value'],
  showXAxis: false,
  showYAxis: false,
  showGridLines: false,
  showLegend: false,
  fillType: 'solid',
})

Value Format Options

PropertyDescriptionTypeDefault
typeFormat type'number' | 'currency' | 'percentage''number'
decimalsDecimal precision (0-10)number0
currencyCurrency code (for currency type)string'USD'
currencyDisplayHow to display currency'symbol' | 'code' | 'name''symbol'
notationNumber notation'standard' | 'compact''standard'
localeLocale for formattingstring'en-US'

Available Colors

type ChartColor =
  | 'blue'
  | 'emerald'
  | 'violet'
  | 'amber'
  | 'gray'
  | 'cyan'
  | 'pink'
  | 'lime'
  | 'fuchsia'
  | 'red'
  | 'green'
  | 'yellow'

On this page