开发者

Highcharts displaying Date axis from milliseconds

How do I display the date on my x axis from a json object structured like so;

[
    [
        634420512000000000,
        100000
    ],
    [
        634421376000000000,
        100086
    ],
    [
        634422240000000000,
        100171
    ],
    [
        634423104000000000,
        100257
    ]
]

Where my date is in milliseconds. I have set my xAxis like so;

xAxis: {
    title: {
        text: 'Time'
    },
    typ开发者_开发百科e: 'datetime'
}


Highcharts accepts three primary formats for data:

  • A simple array (e.g. [1, 2, 3])
  • An array of arrays of x, y pairs (e.g. [[x, y], [x2, y2]])
  • A list of point objects

Further details on these formats can be found in the highcharts documentation. However, in your case, it should be quite easy. Just do something like the following.

var data = []; //assume data is the array you've listed in your question

var chart = new Highcharts.chart({
    xAxis: {
        title: {
            text: 'Time'
        },
        type: 'datetime'
    },
    series: [{
        data: data
    }]
});


Turns out I was returning ticks instead of milliseconds from 1/1/1970

So...

Dim dt1970 As DateTime = New DateTime("1970", "1", "1")
Dim d As DateTime = row("myDateFromDB")
Dim span As TimeSpan = d - dt1970

Dim milli as long = span.TotalMilliseconds
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜