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' });| Categories | Time axis |
|---|---|
Date objects | yes |
ISO texts: 2024-03, 2024-03-01, 2024-03-01T08:30, …Z | yes |
| Timestamps (milliseconds) | with xScale: 'time' |
| Anything else | names, 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: trueandthinwork as with names: ticks follow the part shown.zones,linesandannotationstake dates:{ from: '2024-02-01', to: '2024-02-15' },{ at: '2024-03-01', label: 'Launch' }.- Horizontal charts keep their categories as names.