Which date format is required when the axis type is ‘datetime’ in Highcharts, datetime, timestamp?

I have provided a UNIX timestamp which is used to plot the data for a duration of 8 hours. However, it does not display the date on the chart. When the axis is set to ‘datetime’, I am unsure of the required date format. Can I pass the data as a string or in a different format? According to the documentation, timestamps in milliseconds should be used. For a live demonstration, you can visit http://jsfiddle.net/BlackLabel/8sqafr27/. The API reference can be found at https://api.highcharts.com/highcharts/xAxis.type.


Question:

I’m new to Highcharts and facing a question regarding the ‘datetime’ type axis. I would like to know what date format is required when using this type. Is it limited to only timestamps? For example:

const options: Options = {
        chart: {
            type: 'column',
        },
        xAxis: {
            crosshair: false,
            type: 'datetime', 
            title: {
                text: 'test X,
            },
            labels: {
                format: '{value:%m.%Y}', // here I formate to date
            },
        },
        yAxis: {
            title: {
                text: 'test Y',
            },
        },
        series: [
            {
                name: 'test 1',
                data: [
                    [1483232400000, 1.4],
                    [1483491600000, 5.5],
                ],
            },
            {
                name: 'test 2',
                data: [
                    [1483232400000, 2.4],
                    [1483491600000, null],
                ],
            },
        ],
    };

Is it possible to pass data using a string in this manner?

data: [
        ['2021/12/28', 1.4],
        ['2022/01/28', 1.3],...

or like this:

data: [
        ['28.12.2021', 1.4],
        ['28.01.2022', 1.3],...


Solution:

Accorging to the documentation:


type

The axis can have various types, including linear, logarithmic, datetime, or category. In the case of a linear axis, the numbers are measured in milliseconds and tick marks are positioned based on specific values such as full hours or days. For a category axis, the chart’s series point names are utilized as categories, unless a categories array is specified.

It is necessary to employ millisecond timestamps.

  series: [{
    data: [
      [new Date('2021/12/28').getTime(), 1.4],
      [new Date('2022/01/28').getTime(), 1.3],
      [new Date('2022/02/28').getTime(), 1.3]
    ]
  }]

A live demonstration can be accessed at the following link: http://jsfiddle.net/BlackLabel/8sqafr27/.

The API reference for the xAxis.type can be found at https://api.highcharts.com/highcharts/xAxis.type.

Frequently Asked Questions