Link to home
Start Free TrialLog in
Avatar of sasnaktiv
sasnaktivFlag for United States of America

asked on

How can I get JpGraph to populate arrays from GET or POST or MySQL

Jpgraph only functions if I populate the array by typing in the actual numbers.
The original jpgraph code below functions properly.
But what good is it if $ydata = array() will not parce the data supplied by GET or POST or even harvested from MySQL ???
It's all PHP so what's the big deal?
There has to be a solution. Does anybody know what it is?


<?php // content="text/plain; charset=utf-8"
require_once ('../jpgraph.php');
require_once ('../jpgraph_line.php');

// Original jpgraph code below - This functions properly - But what good is it if I can't GET or POST or even harvent the data from MySQL ???
//$ydata = array(131,132,137,132,139,153,120,153,150,152,120,129,144);

// My attempt to insert values into array below.
$Report_Data_1=$_GET['Report_Data_1']; // FYI: $Report_Data_1 definitely contains the proper values via GET.
$ydata = array($Report_Data_1);

// Create the graph. These two calls are always required
$graph = new Graph(350,250);
$graph->SetScale('textlin');

// Create the linear plot
$lineplot=new LinePlot($ydata);
$lineplot->SetColor('blue');

// Add the plot to the graph
$graph->Add($lineplot);

// Display the graph
$graph->Stroke();
?>


NOTE: The following is what is returned:
The follow treatment results in a 25044 error:
$ydata = array($Report_Data_1);
JpGraph Error: 25044 Cannot use auto scaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).

This treatment results in a 25068 error:
$ydata = $_GET['Report_Data_1'];
JpGraph Error: 25068 A plot has an illegal scale. This could for example be that you are trying to use text auto scaling to draw a line plot with only one point or that the plot area is too small. It could also be that no input data value is numeric (perhaps only '-' or 'x')

I've also received the following error on occasion:
JpGraph Error: 25121 Empty input data array specified for plot. Must have at least one data point.
Avatar of jrm213jrm213
jrm213jrm213
Flag of United States of America image

if your data is coming through as a comma delimited string then array is going to only see 1 long string value, but you can use explode to turn a comma delimited string into an array.

you will want to make sure that you actually have some data in $_GET['Report_Data_1']

$ydata = explode(",",$_GET['Report_Data_1']);

Avatar of sasnaktiv

ASKER


Thanks for getting back to me.
I think that JpGraph requires a comma delimited string because the following functions properly:
$ydata = array(131,132,137,132,139,153,120,153,150,152,120,129,144);

$_GET['Report_Data_1'] contains the proper values. I can call it up on the same page.
And it has the same array values: 131,132,137,132,139,153,120,153,150,152,120,129,144

It functions properly when the array is entered manually as in:
$ydata = array(131,132,137,132,139,153,120,153,150,152,120,129,144);

It fails when the array is a $ValueOfAnyKind

What do you think?
JpGraph requires an array, thats why when you enter it manually, it works for example:

//manually
$ydata = array(131,132,137,132,139,153,120,153,150,152,120,129,144); //works

//basically what you are doing using $_GET to retrieve a comma delimited string
$mydata = "131,132,137,132,139,153,120,153,150,152,120,129,144";
$ydata = array($mydata); // probably doesn't work

$mydata = explode(",","131,132,137,132,139,153,120,153,150,152,120,129,144");
$ydata = array($mydata); //probably works


explode creates an array from a comma delimited string similar to how array() creates an array from a list. A list is different than a comma delimited string.

Okay I think I got the picture.

The following should work. What do you think?
I'll try it and let you know, unless you see a big mistake I'm making.

$mydata = explode($_GET['Report_Data_1']);
$ydata = array($mydata);

Nope!
Here's what I get with that effort:

Warning: Wrong parameter count for explode() in /home/content/p/h/a/pharmacallmobi/html/VXML/jpgraph/src/Examples/RJV_test.php on line 10
JpGraph Error: 25044 Cannot use auto scaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).
if it is a comma delimited string:

$mydata = explode(",",$_GET['Report_Data_1']);
$ydata = array($mydata);


$mydata = explode(",","131,132,137,132,139,153,120,153,150,152,120,129,144");
$ydata = array($mydata);

Result:
JpGraph Error: 25044 Cannot use auto scaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).
$mydata = explode(",",$_GET['Report_Data_1']);
$ydata = array($mydata);

Gives me:
JpGraph Error: 25044 Cannot use auto scaling since it is impossible to determine a valid min/max value of the Y-axis (only null values).
ASKER CERTIFIED SOLUTION
Avatar of jrm213jrm213
jrm213jrm213
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

There should be more idiots in the world just like you!

$mydata = explode(",","$_GET[Report_Data_1]");
$ydata =$mydata;

Functions beautifully.
Thank you very very much!
If it's not one thing it's another!

$datax=array("05/01/10","05/02/10","05/03/10","05/04/10","05/06/10","05/09/10","05/17/10","05/18/10","05/19/10","05/20/10","05/22/10","05/23/10","09/01/10",);

The above functions properly.

But the code below (which value is: "05/01/10","05/02/10","05/03/10","05/04/10","05/06/10","05/09/10","05/17/10","05/18/10","05/19/10","05/20/10","05/22/10","05/23/10","09/01/10","09/02/10","09/03/10","09/04/10","09/05/10","09/07/10","09/08/10","09/08/10",)
Does not!
$myday = explode(",","$_GET[Report_Day]");
$datax = $myday;

It just gives me the graph with 13 numbered tick marks. There should be 20. No dates!

Any logic here?
It could be caused by the trailing comma at the end of your $_GET value, but that doesn't explain why it would show points. I believe Explode should just add an empty value as the last element of the array. Also, you have 09/08/10 listed twice in your data, I don't know if that will cause a problem with jpgraph or not...

The trailing comma does not seem to be the problem because it's in the following statement works ok:
$datax=array("05/01/10","05/02/10","05/03/10","05/04/10","05/06/10","05/09/10","05/17/10","05/18/10","05/19/10","05/20/10","05/22/10","05/23/10","09/01/10","09/02/10","09/03/10","09/04/10","09/05/10","09/07/10","09/08/10","09/08/10",);

The repetition of 09/08/10 doesn't matter either 'cause it doesn't know it's a date.

Keep in mind that the solution to the earlier problem works:
$mydata = explode(",","$_GET[Report_Data_1]");
$ydata =$mydata;

So why shouldn't the same logic hold true for:
$myday = explode(",","$_GET[Report_Day]");
$datax = $myday;

Any thoughts?



Never mind. I figured out where I screwed up!
Thanks for the help.