• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6643
  • Last Modified:

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.
0
sasnaktiv
Asked:
sasnaktiv
  • 9
  • 5
1 Solution
 
jrm213jrm213Commented:
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']);

0
 
sasnaktivAuthor Commented:

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?
0
 
jrm213jrm213Commented:
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.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sasnaktivAuthor Commented:

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);
0
 
sasnaktivAuthor Commented:

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).
0
 
jrm213jrm213Commented:
if it is a comma delimited string:

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


$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).
0
 
sasnaktivAuthor Commented:
$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).
0
 
jrm213jrm213Commented:
thats because i'm an idiot... got caught up in copy and paste.

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

explode creates an array so you don't want to call array on it again.

0
 
sasnaktivAuthor Commented:

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!
0
 
sasnaktivAuthor Commented:
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?
0
 
jrm213jrm213Commented:
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...
0
 
sasnaktivAuthor Commented:

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?


0
 
sasnaktivAuthor Commented:

Never mind. I figured out where I screwed up!
Thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now