Highchart时间格式 [英] Highchart timedate format

查看:231
本文介绍了Highchart时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎完成了我的高图,但我无法设法使日期时间/时间戳看起来正确。我不知道它的xAxis格式,或者它的系列格式。

I'm almost done with my highchart, but I can't manage to get the datetime/timestamp look correct. im not sure if its the format for the xAxis, or if its the format for the serie.

我的数据:
[{x:2016-04-08 12:11:02,y:32} ,{x:2016-04-08 14:22:07,y:2},{x:2016-04-11 10:10:06,y:4} ,{x:2016-04-11 11:56:35,y:2},{x:2016-04-11 12:16:20,y:2} ,{x:2016-04-11 14:09:27,y:2},{x:2016-04-11 15:03:31,y:1} ,{x:2016-04-11 20:18:41,y:1172},{x:2016-04-11 21:00:06,y:1014} ]

$('#container').highcharts('StockChart', {
        rangeSelector : {
            selected : 1
        },
        xAxis: {
            type: 'datetime'
        },
        title : {
            text : 'test'
        },
        series : [{
            name : 'signups',
            data : data,
            turboThreshold : 0
        }]
    });

我确定它缺少一件小事。谢谢

Im sure its a minor thing I am missing. Thanks

推荐答案

对于您的每个日期,将其转换为 Date.UTC

For each of your date convert it to Date.UTC

var date = new Date(yourData[i].x);
var year = date.getFullYear();
var month = date.getMonth();
var day = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
console.log(new Date(Date.UTC(year, month, day, hours, minutes, seconds)));

然后将它插入到您的系列
可能会很长,但它会起作用。
看看这个 FIDDLE

Then insert it to your series May be quite long but, it will work. Look at this FIDDLE:

这篇关于Highchart时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆