• 0

Javascript/JQuery Plotting live graphs


Question

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);
?>
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

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

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.