Sign in to follow this  
Followers 0
Craig Hopson

Javascript/JQuery Plotting live graphs

2 posts in this topic

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);
?>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.