Solved

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

Posted on 2010-09-08
14
6,177 Views
Last Modified: 2012-08-13
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
Comment
Question by:sasnaktiv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
14 Comments
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33630350
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
 
LVL 1

Author Comment

by:sasnaktiv
ID: 33630591

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
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33630636
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:sasnaktiv
ID: 33630807

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
 
LVL 1

Author Comment

by:sasnaktiv
ID: 33630860

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
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33630936
if it is a comma delimited string:

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

Author Comment

by:sasnaktiv
ID: 33631003


$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
 
LVL 1

Author Comment

by:sasnaktiv
ID: 33631052
$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
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 500 total points
ID: 33631090
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
 
LVL 1

Author Closing Comment

by:sasnaktiv
ID: 33631192

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
 
LVL 1

Author Comment

by:sasnaktiv
ID: 33632025
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
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33632162
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
 
LVL 1

Author Comment

by:sasnaktiv
ID: 33632337

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
 
LVL 1

Author Comment

by:sasnaktiv
ID: 33637998

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question