Code récupéré sur experts-exchange concernant le refresh Automatique de graphes JQPLOT

Introduction:

A la recherche d’un code concernant le refresh automatique de données sur un graphe jqplot, j’ai trouvé ce code à tester:

Code:

Ticker: Update HTML

var l1 = [50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50];
var l2 = [150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150,150];
var l3 = [250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250];
var l4 = [350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350];

function updateGraph(n1, n2, n3, n4) {

l1.shift();
l1.push(n1);
l2.shift();
l2.push(n2);
l3.shift();
l3.push(n3);
l4.shift();
l4.push(n4);

$('#chart1').html('');

$.jqplot('chart1', [l1, l2, l3, l4], {
legend:{show:true,location:'sw',xoffset: 3,yoffset: 3},
series:[
{label: 'Item 1'},
{label: 'Item 2'},
{label: 'Item 3'},
{label: 'Item 4'}
]
});
}

setInterval(function(){updateGraph( (Math.floor(Math.random()*50)+10) , (Math.floor(Math.random()*50)+100) , (Math.floor(Math.random()*50)+200) , (Math.floor(Math.random()*50)+300) );}, 500);
updateGraph( (Math.floor(Math.random()*85)+10) , (Math.floor(Math.random()*85)+100) , (Math.floor(Math.random()*100)+200) , (Math.floor(Math.random()*100)+300) );

obj=document.getElementById('recentNumbers');
if (obj) obj.innerHTML=l1;

codeshit

Publicités