wormy bastaard
New Member
What I am trying to do is play a little animation every time a value increases or decreases. With this code I'm updating my value every second from an XML source. The animation should only be executed when the value increases. So if my value is 62 and it is updated to 62, no animation should be executed. When my value is 62 and it is updated to 63, that's when I want this animation to happen. Does anyone know how to modify this code to make that happen?\[code\]function updateAll(){$.ajax({ type: "GET", url: "/ajax/ajax.updatedata.php", data: "", success: function(html){ html = JSON.parse(html); if(html instanceof Object) { // projecten $('#projecten-aantal').html(html['projecten'][0]['waarde']); $('#projecten-afgerond').html(html['projecten'][1]['waarde']); var projecten_aantal = parseInt(html['projecten'][0]['waarde']); var projecten_afgerond = parseInt(html['projecten'][1]['waarde']); var sampleDataProjecten = [ { naam: html['projecten'][0]['naam'], waarde: parseInt(html['projecten'][0]['waarde']), percent: parseFloat(html['projecten'][0]['percent'])}, { naam: html['projecten'][1]['naam'], waarde: parseInt(html['projecten'][1]['waarde']), percent: parseFloat(html['projecten'][1]['percent'])} ]; var settingsProjecten = { enableAnimations: false, source: sampleDataProjecten }; $('#pie-chart-projecten').jqxChart(settingsProjecten); $('#pie-chart-projecten').jqxChart('refresh'); // domeinwinkel var aantalRegistraties = 0; for(var i=0;i<=6;i++) { aantalRegistraties += parseInt(html['domeinwinkel']['waarde']); } $('#domeinwinkel-registraties').html(aantalRegistraties); var sampleDataDomeinwinkel = [ { naam: html['domeinwinkel'][5]['naam'], waarde: parseInt(html['domeinwinkel'][5]['waarde']) }, { naam: html['domeinwinkel'][4]['naam'], waarde: parseInt(html['domeinwinkel'][4]['waarde']) }, { naam: html['domeinwinkel'][3]['naam'], waarde: parseInt(html['domeinwinkel'][3]['waarde']) }, { naam: html['domeinwinkel'][2]['naam'], waarde: parseInt(html['domeinwinkel'][2]['waarde']) }, { naam: html['domeinwinkel'][1]['naam'], waarde: parseInt(html['domeinwinkel'][1]['waarde']) }, { naam: html['domeinwinkel'][0]['naam'], waarde: parseInt(html['domeinwinkel'][0]['waarde']) }, { naam: html['domeinwinkel'][6]['naam'], waarde: parseInt(html['domeinwinkel'][6]['waarde']) } ]; var settingsDomeinwinkel = { enableAnimations: false, source: sampleDataDomeinwinkel }; $('#line-chart-domeinwinkel').jqxChart(settingsDomeinwinkel); $('#line-chart-domeinwinkel').jqxChart('refresh'); // serverload var barcolors = new Array(); //Serverload bars for(var i=0;i<=6;i++) { var setBarWidth = (parseFloat(html['servers']['waarde'])/2)*100; if(setBarWidth > 100) { barcolors = 100; } else { barcolors = setBarWidth; } } $("[id^=serverload]").filter(function() { var i = this.id.substring(10), width = barcolors[i-1]; if (width !== undefined) this.style.width = width + "%"; return width > 50; }).addClass("redbar"); $("[id^=serverload]").filter(function() { var i = this.id.substring(10), width = barcolors[i-1]; if (width !== undefined) this.style.width = width + "%"; return width <= 50; }).removeClass("redbar"); } else { console.log('Fout bij het updaten van de data: html is geen array'); console.log(html); } }});\[/code\]}More information about the code above:The code above is to update values (span elements with text inside and JQuery line and pie charts) which will be retrieving from an XML file which contains the data in the following sequence (translated):\[code\]<root> <projects> <entry> <name>Total</name> <value>10</value> <percent>100</percent> </entry> <entry> <name>Finished</name> <value>5</value> <percent>50</percent> </entry> </projects> <tasks> <entry> <name>Total</name> <value>20</value> </entry> </tasks> etc.</root>\[/code\]The XML file will be updated by a cron job, so there's no direct use of a database or a hidden field to save the value.