Configuring the time format

Properties that are specific for time scales are configured in the axis.time property. It receives an object. Some of these properties are listed as follows:

Property

Value

Description

unit

millisecond, second, minute, hour, day, week, month, quarter, year

The unit of time to consider for the data.

stepSize

Number

The minimum step between values in the scale (this may group several values in a single tick).

displayFormats

Object, containing zero or more time units as String properties

This object is used to override the default string format used for each unit. See supported tokens below.

tooltipFormat

A string with a date format, such as MMMM, YYYY, or h:mm:ss

A format string to display data/time information in tooltips. See supported tokens below.

Selected properties of the axis.time object

Time scales use moment.js formats, which are based on standard date/time formatting tokens. The default formats for each unit and the output they produce are listed as follows:

Unit

Default format

Output example

Millisecond

h:mm:ss.SSS A

2:07:36.976 PM

Second

h:mm:ss A

2:07:36 PM

Minute

h:mm A

2:07 PM

Hour

hA

2 PM

Day

MMM D

Feb 24

Week

ll

Feb 24 2019

Month

MMM YYYY

Feb 2019

Quarter

[Q]Q - YYYY

Q1 – 2019

Year

YYYY

2019

Default time unit formats used in time scales

If you wish to format date/time in a specific way, you can use the axis.time.displayFormats property to override the default format for the time units you are using:

time: {
unit: 'month',
displayFormats: {
month: 'MMMM', // will print January, February,… for month units
}
}

You can combine the following tokens and create a string:

Property

Tokens

Output

Day of month

D, Do, DD

1 2 … 31, 1st 2nd … 31st, 01 02 … 31

Day of week

d, ddd, dddd

0 1 … 6, Sun Mon … Sat, Sunday, Monday … Saturday

Month

M, MM, MMM, MMMM

1 2 … 12, 01 02 … 12, Jan Feb … Dec, January February … December

Quarter

Q, Qo

1 2 3 4, 1st 2nd 3rd 4th

Year

YYYY, Y

1970 1971 … 2030, 1970 1971 … 9999

AM/PM

A, a

AM PM, am pm

AM/PM

A, a

AM PM, am pm

Hour

H, HH, h, hh

0 1 … 23, 00 01 … 23, 1 2 … 12, 01 02 … 12

Minute

m, mm

0 1 … 59, 00 01 … 59

Second

s, ss

0 1 … 59, 00 01 … 59

Millisecond

SSS

000 001 … 999

Time zone

ZZ

-0700 -0600 … +0700

Most common tokens for creating date-string formats

There are also other localized formats. See additional options in the documentation for moment.js (momentjs.com/docs/#/displaying/format).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset