Toolforge Docs
DocsBlock OutputslineChart

lineChart

Create line charts to display trends and changes over continuous data.

Usage

Line chart

const chart = block.lineChart({
  title: 'Stock Price',
  data: [
    { date: '2024-01', price: 150 },
    { date: '2024-02', price: 165 },
    { date: '2024-03', price: 142 },
  ],
  index: 'date',
  categories: ['price'],
})

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 line series(keyof T)[]Yes
colorsColors for each category seriesChartColor[]No['blue']
xAxisLabelLabel for the x-axisstringNoundefined
yAxisLabelLabel for the y-axisstringNoundefined
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 a LineChartOutput object that can be returned from a handler or passed to io.message().

Examples

Multi-series line chart

Multi-series line chart

return block.lineChart({
  title: 'Temperature Comparison',
  data: temperatureData,
  index: 'month',
  categories: ['thisYear', 'lastYear', 'average'],
  colors: ['blue', 'gray', 'emerald'],
})

With axis labels

With axis labels

return block.lineChart({
  title: 'Response Time',
  description: 'API response times over the past 24 hours',
  data: responseData,
  index: 'time',
  categories: ['p50', 'p95', 'p99'],
  colors: ['emerald', 'amber', 'red'],
  xAxisLabel: 'Time',
  yAxisLabel: 'Milliseconds',
})

Minimal sparkline-style

Minimal sparkline-style

return block.lineChart({
  data: trendData,
  index: 'time',
  categories: ['value'],
  showXAxis: false,
  showYAxis: false,
  showGridLines: false,
  showLegend: false,
})

With percentage formatting

With percentage formatting

return block.lineChart({
  title: 'Conversion Rate',
  data: conversionData,
  index: 'week',
  categories: ['rate'],
  valueFormat: {
    type: 'percentage',
    decimals: 2,
  },
})

On this page