2016-04-03 105 views
2

我想用Highcharts从我的数据库中可视化温度。 的JS数据阵列看起来如下:来自JS日期的Highcharts X轴时间

[date object, value] 

例如:

[Fri Mar 04 2016 01:39:10 GMT+0100 (Central Europe Standard Time), 20.5] 

正如你可以看到,我有约会对象和一个值。所以我的问题是格式化X轴,它显示我的日期,最好格式化为HH:MM。这似乎是我使用xAxis类型的日期时间,但这不起作用。

xAxis: { 
    type: 'datetime' 
    // ... 
} 

你知道这个问题的解决方案吗?

Image of graph

+0

你能后的代码?我们需要看到图表试图知道要修复的东西 – JordanHendrix

回答

4

Highcharts取入datetime在毫秒的时间戳的形式。您正在提供一个Date对象。而不是仅仅插入Date对象,而是使用Date对象的getTime()函数来获取时间戳。

例如(JSFiddle):

$(function() { 
    // The timestamp of the current time 
    var timestampNow = new Date().getTime(); 
    // The timestamp one hour from now 
    var timestampOneHour = new Date(timestampNow + (3600 * 1000)).getTime(); 

    $('#container').highcharts({ 
     xAxis: { 
      type: 'datetime' 
     }, 
     series: [{ 
      data: [ 
       [timestampNow, 1], 
       [timestampOneHour, 2] 
      ] 
     }] 
    }); 
}); 
+0

ty对于您的快速帮助非常重要:) – Fabian