Time Cartesian Axis
The time scale requires both a date library and a corresponding adapter to be present. Please choose from the .
Data Sets
See data structures.
When providing data for the time scale, Chart.js uses timestamps defined as milliseconds since the epoch (midnight January 1, 1970, UTC) internally. However, Chart.js also supports all of the formats that your chosen date adapter accepts. You should use timestamps if you’d like to set for better performance.
Namespace: options.scales[scaleId]
Namespace: options.scales[scaleId]
Time Units
The following time measurements are supported. The names can be passed as strings to the time.unit
config option to force a certain unit.
'millisecond'
'second'
'minute'
'hour'
'day'
'week'
'month'
'quarter'
For example, to create a chart with a time scale that always displayed units per month, the following config could be used.
Display Formats
You may specify a map of display formats with a key for each unit:
millisecond
second
minute
hour
day
week
month
quarter
year
The format string used as a value depends on the date adapter you chose to use.
For example, to set the display format for the quarter
unit to show the month and year, the following config might be passed to the chart constructor.
Ticks Source
'auto'
: generates “optimal” ticks based on scale size and time options'data'
: generates ticks from data (including labels from data{x|y}
objects)
Parser
If this property is defined as a string, it is interpreted as a custom format to be used by the date adapter to parse the date.
If this is a function, it must return a type that can be handled by your date adapter’s parse
method.
Min Max Configuration
For both the min
and max
properties, the value must be string
that is parsable by your date adapter or a number with the amount of milliseconds that have elapsed since UNIX epoch. In the example below the x axis will start at 7 October 2021.
When changing the scale type from Time scale to Logarithmic/Linear scale, you need to add bounds: 'ticks'
to the scale options. Changing the bounds
parameter is necessary because its default value is the for the Time scale.
Initial config:
Internal data format
Internally time scale uses milliseconds since epoch