Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Populate Graph 1

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
I am trying to dynamically produce a graph (using jp graph) from a database.

Getting the information from the database is not the problem.

This is where I am at the moment
Code:
//This line simulates info from the database
$xaxis="0,0,0,0,0,0,0,0,0,839,762,769,690,530,517,450,297,9,0,0,0,0,0,0";

//To work properly this is how it must appear
//$data1y=array(0,0,0,0,0,0,0,0,0,839,762,769,690,530,517,450,297,9,0,0,0,0,0,0);

$test="array(".$xaxis.");";
eval("\$test = \"$test\";");
$data1y=$test;
I am getting the following message on screen

array(0,0,0,0,0,0,0,0,0,839,762,769,690,530,517,450,297,9,0,0,0,0,0,0);JpGraph Error Either X or Y data arrays contains non-numeric values. Check that the data is really specified as numeric data and not as strings. It is an error to specify data for example as '-2345.2' (using quotes).


Thanking in advance for any help received
 
i don't think you are using eval right.

try this instead:
Code:
//This line simulates info from the database
$xaxis="0,0,0,0,0,0,0,0,0,839,762,769,690,530,517,450,297,9,0,0,0,0,0,0";

//To work properly this is how it must appear
//$data1y=array(0,0,0,0,0,0,0,0,0,839,762,769,690,530,517,450,297,9,0,0,0,0,0,0);
eval('$data1y=array('.$xaxis.');');
print_r($data1y);
 
Thats worked, thanks.

Believe it or not I had tried this as well but used double quotes instead and it didn't work.

For other peoples reference you don't need the "print_r($data1y);" part for the array to work in the graph.
 
sorry. that was lazy of me. I'd made an assumption that you actively wanted to use eval().

you, of course, should not be using eval for this. there are better/neater ways of doing so.

ideally the array would be build directly from the database, but if for some reason you have the entire string in a single column, you should instead use this code:

Code:
$xaxis="0,0,0,0,0,0,0,0,0,839,762,769,690,530,517,450,297,9,0,0,0,0,0,0";
$data1y = explode(',',$xaxis);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top