2013-04-08 120 views
0

我已經在Stackoverflow中搜索了有關此日期問題的修復程序中的高和低。我真的很努力地讓日期顯示在圖表上,點正確地設置在它們上面。無法使Highcharts x軸日期工作

這裏是JS腳本:

$(document).ready(function() { 
          var options = { 
           chart: { 
             renderTo: 'drawing', 
             zoomType: 'x', 
             width: 900, 
             height: 222 
            }, 
            exporting: { 
             enabled: true  
            }, 
            title: { 
             text: url+' - '+keyword 
            }, 
            credits: { 
             text: 'Testing', 
             href: '' 
            }, 
            xAxis: { 
             type: 'datetime' 
            }, 
            yAxis: [{ 
             allowDecimals: false, 
             reversed: true, 
             title: { 
              text: 'Rankings' 
             } 
            },], 
            tooltip: { 
             crosshairs: true, 
             shared: true 
            }, 
            series: [{}] 
          }; 

           var url = "****/chart.php"; 
           $.getJSON(url, function(data1){        

           options.series = data1; 
           var chart = new Highcharts.Chart(options); 
          });       
         }); 

這是我們的PHP腳本生成的JSON

[{"name":"Google Rank","data":[["Date.UTC(2013, 3, 08)",23],["Date.UTC(2013, 3, 05)",24],["Date.UTC(2013, 3, 04)",23],["Date.UTC(2013, 3, 03)",22],["Date.UTC(2013, 3, 02)",24],["Date.UTC(2013, 3, 01)",26],["Date.UTC(2013, 2, 31)",24],["Date.UTC(2013, 2, 30)",24],["Date.UTC(2013, 2, 29)",25],["Date.UTC(2013, 2, 28)",25],["Date.UTC(2013, 2, 27)",25],["Date.UTC(2013, 2, 26)",26],["Date.UTC(2013, 2, 25)",25],["Date.UTC(2013, 2, 24)",24],["Date.UTC(2013, 2, 23)",0],["Date.UTC(2013, 2, 22)",10],["Date.UTC(2013, 2, 21)",10],["Date.UTC(2013, 2, 20)",10],["Date.UTC(2013, 2, 19)",10],["Date.UTC(2013, 2, 18)",10],["Date.UTC(2013, 2, 17)",10],["Date.UTC(2013, 2, 16)",9],["Date.UTC(2013, 2, 15)",9],["Date.UTC(2013, 2, 14)",9],["Date.UTC(2013, 2, 13)",9]],"visible":true,"pointInterval":86400000,"showInLegend":true},{"name":"Bing Rank","data":[["Date.UTC(2013, 3, 08)",0],["Date.UTC(2013, 3, 05)",0],["Date.UTC(2013, 3, 04)",0],["Date.UTC(2013, 3, 03)",0],["Date.UTC(2013, 3, 02)",0],["Date.UTC(2013, 3, 01)",0],["Date.UTC(2013, 2, 31)",0],["Date.UTC(2013, 2, 30)",0],["Date.UTC(2013, 2, 29)",0],["Date.UTC(2013, 2, 28)",0],["Date.UTC(2013, 2, 27)",0],["Date.UTC(2013, 2, 26)",0],["Date.UTC(2013, 2, 25)",0],["Date.UTC(2013, 2, 24)",0],["Date.UTC(2013, 2, 23)",0],["Date.UTC(2013, 2, 22)",0],["Date.UTC(2013, 2, 21)",0],["Date.UTC(2013, 2, 20)",0],["Date.UTC(2013, 2, 19)",0],["Date.UTC(2013, 2, 18)",0],["Date.UTC(2013, 2, 17)",0],["Date.UTC(2013, 2, 16)",0],["Date.UTC(2013, 2, 15)",0],["Date.UTC(2013, 2, 14)",0],["Date.UTC(2013, 2, 13)",0]],"visible":true,"pointInterval":86400000,"showInLegend":true},{"name":"Yahoo Rank","data":[["Date.UTC(2013, 3, 08)",0],["Date.UTC(2013, 3, 05)",0],["Date.UTC(2013, 3, 04)",0],["Date.UTC(2013, 3, 03)",0],["Date.UTC(2013, 3, 02)",0],["Date.UTC(2013, 3, 01)",0],["Date.UTC(2013, 2, 31)",0],["Date.UTC(2013, 2, 30)",0],["Date.UTC(2013, 2, 29)",0],["Date.UTC(2013, 2, 28)",0],["Date.UTC(2013, 2, 27)",0],["Date.UTC(2013, 2, 26)",0],["Date.UTC(2013, 2, 25)",0],["Date.UTC(2013, 2, 24)",0],["Date.UTC(2013, 2, 23)",0],["Date.UTC(2013, 2, 22)",0],["Date.UTC(2013, 2, 21)",0],["Date.UTC(2013, 2, 20)",0],["Date.UTC(2013, 2, 19)",0],["Date.UTC(2013, 2, 18)",0],["Date.UTC(2013, 2, 17)",0],["Date.UTC(2013, 2, 16)",0],["Date.UTC(2013, 2, 15)",0],["Date.UTC(2013, 2, 14)",0],["Date.UTC(2013, 2, 13)",0]],"visible":true,"pointInterval":86400000,"showInLegend":true}] 

回答

0

在JSON無法使用功能,如Date.UTC(),所以我的建議使用時間戳編號。

+0

嗨,謝謝你的回覆。首先,我已經改變了它,所以他們現在發出時間戳,但圖表顯示了「時間」,例如:18:40,18:45,18:50,18:55等等。然後當我將鼠標懸停在每個點,我只能查看第一個和最後一個點.. – 2013-04-08 11:16:45

+0

你是否按x排序數據,升序? – 2013-04-08 11:17:42

+0

我不太確定..上面的JS代碼仍然和現在一樣。 – 2013-04-08 11:19:04