Vincent
Vincent

Reputation: 852

Display datetime including milliseconds

Is it possible to display in highcharts x axis with a datetime including the milliseconds? i have a different data recorded on the same time and seconds but different milliseconds. Here's my sample data.

[
[
    "1507104333940",
    209.231
],
[
    "1507104333950",
    208.715
],
[
    "1507104333960",
    207.933
],
[
    "1507104333970",
    207.112
],
[
    "1507104333980",
    206.634
],
[
    "1507104333990",
    206.638
],
[
    "1507104334000",
    206.132
],
[
    "1507104334010",
    205.197
],
[
    "1507104334020",
    204.713
],
[
    "1507104334030",
    204.415
]]

But in highcharts it only display date and time (HH:MM:SS). I want to display it with milliseconds (HH:MM:SS.Mi)

Upvotes: 0

Views: 268

Answers (1)

Hassan Imam
Hassan Imam

Reputation: 22534

You can use xAxis.dateTimeLabelFormats. Specify the timeformat to be millisecond: '%H:%M:%S.%L'

var data = [ [ "1507104333940", 209.231 ], [ "1507104333950", 208.715 ], [ "1507104333960", 207.933 ], [ "1507104333970", 207.112 ], [ "1507104333980", 206.634 ], [ "1507104333990", 206.638 ], [ "1507104334000", 206.132 ], [ "1507104334010", 205.197 ], [ "1507104334020",204.713 ], [ "1507104334030", 204.415 ]].map(a => [+a[0], a[1]]);;
Highcharts.chart('chart', {
  title: {
    text: 'Chart with time'
  },
  xAxis: {
    type: 'datetime',
    dateTimeLabelFormats: {
      millisecond: '%H:%M:%S.%L'
    }
  },
  series: [{
    data: data
  }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="chart"></div>

Upvotes: 2

Related Questions