Jump to content



Photo

Javascript/JQuery Plotting live graphs


  • Please log in to reply
1 reply to this topic

#1 Craig Hopson

Craig Hopson

    Neowinian

  • Joined: 17-November 12
  • Location: London
  • OS: Windows 8 :-(

Posted 23 August 2013 - 17:55

Hi guys i'm trying to learn about graphs but cant figure out what i'm doing wrong this is a function that was getting random data and plotting.....you will see

//var data = [], totalPoints = 2;
	function getRandomData() {
		//if (data.length > 0)
		//	data = data.slice(1);

		// do a random walk
		//while (data.length < totalPoints) {
		//	var prev = data.length > 0 ? data[data.length - 1] : 50;
		//	var y = prev + Math.random() * 10 - 5;
		//	if (y < 0)
		//		y = 0;
		//	if (y > 200)
		//		y = 200;
		//	data.push(y);
		//}
		$.ajax({
    			url:"getprob.php",  
    			success:function(data) {
    			}
  		});
		// zip the generated y values with the x values
		var res = [];
		for (var i = 0; i < data.length; ++i)
			res.push([i, data[i]])
		return res;
	}

as you can see i commented out the data variable and replaced it with a ajax call but it just dont work

 

FYI

getprob.php

<?php
echo rand(1,200);
?>



#2 jackslade

jackslade

    Neowinian

  • Joined: 13-September 05
  • Location: Indiana

Posted 23 August 2013 - 18:26

Try putting the section after //zip the generated y values with the x values within the success function of the $.ajax call.