Question

I have a gage that refreshes and gets random data every time I click a button.

My question is how can I do this without clicking the button, I want it to Auto refresh every 5 seconds.

 <div id="gg1" class="gauge">
</div>
<a href="#" id="gg1_refresh" class="button grey">Random Refresh</a>
<script>
    var gg1 = new JustGage({
        id: "gg1",
        donut: 1,
        title: "BARTOW",
        titleFontColor: "#000000",
        value: 95.7,
        min: 0,
        max: 100,           
        labelFontColor: "#000000",
        humanFriendlyDecimal: 1,
        decimals: 1,
        symbol: "%",
        refreshAnimationType: "bounce",
        gaugeWidthScale: 0.6,
        customSectors: [{
            color: "#ff0000",
            lo: 0,
            hi: 79
        }, {
            color: "#ffa500",
            lo: 80,
            hi: 89
        }, {
            color: "#1eae1e",
            lo: 90,
            hi: 100
        }],
        counter: true
    });
    $(document).ready(function () {
        $('#gg1_refresh').bind('click', function () {
            gg1.refresh(getRandomInt(0, 100));
            return false;

        });
    });
</script>
Was it helpful?

Solution 2

Check out the following, edited per @thenewseattle's comment.

<script type="text/javascript">
    function refreshDiv() {
       gg1.refresh(getRandomInt(0, 100));
    }
    $(document).ready(function () { setInterval(refreshDiv, 5000); });
</script>

OTHER TIPS

You need to use setInterval to call a function every 5 seconds.

You will need to create a function that contains the code

gg1.refresh(getRandomInt(0, 100));

And then use the setInterval function in your click event handler to call the function you created above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top