2013-10-05 42 views
1

我在模態窗口內顯示jqplot測量儀表,我想每5秒鐘更新一次。我寫了下面的代碼,但它不起作用每5秒更新一次jqplot測量儀表

$(document).ready(function(){ 
s1 = [Math.floor(Math.random()*(401)+100)]; 

plot3 = $.jqplot('meter',[s1],{ 
    seriesDefaults: { 
     renderer: $.jqplot.MeterGaugeRenderer, 
     rendererOptions: { 
      min: 100, 
      max: 500, 
      intervals:[200, 300, 400, 500], 
      intervalColors:['#66cc66', '#93b75f', '#E7E658', '#cc6666'], 
      smooth: true, 
      animation: { 
       show: true 
      } 
     } 
    } 
}); 
$('a[href=\"#yw1_tab_3\"]').on('shown', function(e) { 
      if (plot3._drawCount === 0) { 
      plot3.replot(); 
     } 
     }); 
     windows.setInterval(function() { plot3.destroy(); 
     s1 = [Math.floor(Math.random()*(401)+100)]; 
     plot3.replot(); 
     }, 5000); 
}); 

如何在不更新整個頁面的情況下每5秒更新一次流量計?

回答

2

這裏是修復:JsFiddle link

$(document).ready(function() { 
    var s1 = [Math.floor(Math.random() * (401) + 100)]; 

    var plot3 = $.jqplot('meter', [s1], { 
     seriesDefaults: { 
      renderer: $.jqplot.MeterGaugeRenderer, 
      rendererOptions: { 
       min: 100, 
       max: 500, 
       intervals: [200, 300, 400, 500], 
       intervalColors: ['#66cc66', '#93b75f', '#E7E658', '#cc6666'], 
       smooth: true, 
       animation: { 
        show: true 
       } 
      } 
     } 
    }); 
    setInterval(function() { 
     s1 = [Math.floor(Math.random() * (401) + 100)]; 
     plot3.series[0].data[0] = [1,s1]; //here is the fix to your code 
     plot3.replot(); 
    }, 1000); 
}); 
+0

感謝Gyandeep的解決方案。 – prattom

+0

這個jsfiddle不適合我。我看到其他的例子在jsfiddle上適用於不同的圖表類型,但是沒有一個適用於MeterGauge。任何想法發生了什麼? –

+0

它看起來像jqplot擴展不能再被訪問:「無法加載資源:服務器響應狀態403(禁止)」 –