2017-08-11 43 views
0

DST小時2:00至3:00在高圖上沒有正常銷售。我有以下數據。Highchart:日間節省時間的蠟燭圖不正確DST

[new Date('2017/03/12 01:00:00').getTime(), 10], 
    [new Date('2017/03/12 02:00:00').getTime(), 20], 
    [new Date('2017/03/12 03:00:00').getTime(), 30], 
    [new Date('2017/03/12 04:00:00').getTime(), 40], 
    [new Date('2017/03/12 05:00:00').getTime(), 50] 

檢查小提琴

http://jsfiddle.net/SurenderK/ko8dk2fd/4/

enter image description here

+0

我看起來像它呈現的罰款。 API參考:http://api.highcharts.com/highcharts/global.useUTC。 –

+1

這不是它呈現錯誤 - 而是你對'getTime()'的調用在2:00和3:00:'1489302000000'返回相同的值。我不知道這是爲什麼,但無論'useUTC'設置如何,它都是一樣的。 http://jsfiddle.net/ko8dk2fd/5/ – jlbriggs

+0

這是相同的價值,因爲在凌晨3點夏令時完成,時鐘轉回到2:00。 – ewolden

回答

0

我發現了一個辦法解決這個。問題在於我們發送的縱座標。因爲新的日期()在同一時間爲DST覆蓋2:00和3:00。所以我們需要以毫秒爲單位發送正確的座標。

我使用了一個函數convertInMill,它將時間字符串轉換爲UTC並將時區偏移量加回。

var convertInMill = function(stringDate) { 
    var obj, year, mnth, day, hr, min, sec, timeZoneOffset, timeInMillS; 

    timeZoneOffset = 1; // machine timezone offset with UTC timezone 

    obj = stringDate.split(/[\s/:-]+/); 
    year = obj[0]; 
    mnth = obj[1]; 
    day = obj[2]; 
    hr = obj[3]; 
    min = obj[4]; 
    sec = obj[5]; 

    timeInMillS = Date.UTC(year, mnth - 1, day, hr, min, sec) + (timeZoneOffset * 3600000); 

    return timeInMillS; 
} 

系列日期

series: [{ 
    data: [ 
    [convertInMill('2017/03/12 00:00:00'), 10], 
    [convertInMill('2017/03/12 01:00:00'), 20], 
    [convertInMill('2017/03/12 02:00:00'), 30], 
    [convertInMill('2017/03/12 03:00:00'), 40], 
    [convertInMill('2017/03/12 04:00:00'), 50] 
    ] 
}]`` 

下面搗鼓對我工作的罰款。

http://jsfiddle.net/SurenderK/ko8dk2fd/11/

相關問題