updating jqplot meter gauge after every 5 seconds

 ̄綄美尐妖づ 提交于 2019-12-11 10:58:33

问题


I am displaying jqplot meter gauge inside modal window and I want to update it after every 5 seconds. I wrote the following code but it is not working

$(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);
});

How can I update meter gauge every 5 seconds without updating whole page?


回答1:


here is the fix: 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);
});


来源:https://stackoverflow.com/questions/19196876/updating-jqplot-meter-gauge-after-every-5-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!