Skip to content

Time axis ​

Give dates as categories: an xy chart places them by time, so uneven gaps are drawn to scale.

ts
createChart(host, {
  type: 'xy',
  categories: ['2024-01-01', '2024-01-02', '2024-01-08', '2024-03-15'],
  series: [{ name: 'Orders', data: [4, 6, 7, 9] }],
}, { locale: 'fr-FR' });
CategoriesTime axis
Date objectsyes
ISO texts: 2024-03, 2024-03-01, 2024-03-01T08:30, …Zyes
Timestamps (milliseconds)with xScale: 'time'
Anything elsenames, evenly spaced

xScale: 'category' keeps dates as names, evenly spaced. Dates without a zone are local time.

Ticks ​

Ticks are chosen by the span shown: minutes, hours, days, weeks (Mondays), months, quarters, years or decades. They are written with Intl.DateTimeFormat in the locale of the chart: 14:00, 4 Mar, Jan 2024, 2020. The tooltip writes the date in full, with the time when the data has one.

Bars, zoom and zones ​

  • Bars take the width of the shortest gap between two dates, so they never overlap.
  • zoom: true and thin work as with names: ticks follow the part shown.
  • zones, lines and annotations take dates: { from: '2024-02-01', to: '2024-02-15' }, { at: '2024-03-01', label: 'Launch' }.
  • Horizontal charts keep their categories as names.