2013-09-26 27 views
0

我正在使用JSON將數據提取到我的數據庫。有沒有辦法讓xAxis轉向6小時前,5小時前,4小時前,3小時前,2小時前,1小時前圖表更新?因爲我使用LM35將溫度導入到我的數據庫中。我真的需要你的幫助。 ( 對不起,我的英語不好)。提前致謝。這裏是我的代碼Highchart xAxis「6小時前」,「5小時前」等。而我的圖表正在更新

$(function() { 
$(document).ready(function() { 
    Highcharts.setOptions({ 
     global: { 
      useUTC: false 
     } 
    }); 





$(document).ready(function() { 
     var options = { 
      chart: {   
       renderTo: 'container', 

       type: 'line', 
       marginRight: 130, 
       marginBottom: 65, 
      }, 
      title: { 
       text: 'Temperature Over Time', 
       x: -20 //center 
      }, 
      subtitle: { 
       text: '', 
       x: -20 
      }, 
      xAxis: { 
      tickInterval:12, 
      range:20, 
      categories:[] 
      }, 


      scrollbar: { 
       enabled: true, 
     barBackgroundColor: 'gray', 
     barBorderRadius: 7, 
     barBorderWidth: 0, 
     buttonBackgroundColor: 'gray', 
     buttonBorderWidth: 0, 
     buttonArrowColor: 'yellow', 
     buttonBorderRadius: 7, 
     rifleColor: 'yellow', 
     trackBackgroundColor: 'white', 
     trackBorderWidth: 1, 
     trackBorderColor: 'silver', 
     trackBorderRadius: 7 
      },  


      yAxis: { 
      min:0, 
      max: 40, 
       title: { 
        text: 'Temperature', 
       }, 


       plotLines: [{ 
        value: 0, 
        width: 1, 
        color: '#808080' 
       }] 
       }, 


      tooltip: { 
       formatter: function() { 
         return '<b>'+ this.series.name +'</b><br/>'+ 
         this.x +': '+ this.y; 
       } 

      }, 
      legend: { 
       layout: 'vertical', 
       align: 'right', 
       verticalAlign: 'top', 
       x: -10, 
       y: 100, 
       borderWidth: 0 
      }, 
      series: [] 
     } 

     refreshDiv(); 
     $(window).scrollLeft($(window).width()); 
     setInterval(refreshDiv, 300000); 
     function refreshDiv(){ 
     $.getJSON("data.php", function(json) { 
     options.xAxis.categories = json[0]['data']; 
      options.series[0] = json[1]; 
      chart = new Highcharts.Chart(options); 
     }); 
     } 

    }); 
    }); 
    }); 
+0

您可以放一段代碼,請 –

+0

我發佈了我的代碼。 – EriCkson

回答

0

,而不是驗證碼:

$.getJSON("data.php", function(json) { 
    options.xAxis.categories = json[0]['data']; 
     options.series[0] = json[1]; 
     chart = new Highcharts.Chart(options); 
    }); 

可以使用setCategories功能和setData,但我建議創建的圖表,然後只在本例中使用addPoint功能區間,如: http://www.highcharts.com/demo/dynamic-update。在xAxis不正確的情況下,您可以使用日期時間type並反轉參數](http://api.highcharts.com/highcharts#xAxis.reversed