JPGraph and Arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

JPGraph and Arrays

Post by SBro »

I'm having problems sending an array to jpgraph to process and then use as labels for an axis, I have the following code

page that calls the graph:

Code: Select all

$monthsYears = array("Jan", "Feb", "Mar");
echo '<img src="graphcreate.php?monthsYears='.$monthsYears.'">';
Then in graphcreate.php I have the following

Code: Select all

$monthsYears = $_GET&#1111;'monthsYears'];
$xlabels = array();
for($i = 0; $i < count($monthsYears); $i++) &#123;
	array_push($xlabels, $monthsYears&#1111;$i]);
&#125;
...
$graph->xaxis->SetTickLabels($xlabels);
When the graph loads, on the x axis I get the lables "A, 2, 3" I'm guessing it uses "A" cause it knows it's an array, and 2 and 3 are the default values, it should be returning "Jan, Feb, Mar" however. The array is passing fine, however a count($monthsYears) in graphcreate.php only returns 1, so for some reason the entire array doesn't seem to be getting passed, what am I missing? thankyou.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look into serialize() or join() or some of the other array/variable functions.. because echoing and array variable just prints "Array"
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post by SBro »

Thankyou, had a look and a read on serialize() and join() and from that and other readings, discovered that using sessions was probably easier :) thanks for your help.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

what a coincidence.


im doing the exact same thing today.

using jpgraph and sending a large array through the query string :)

in case your intrested how i did it:

Code: Select all

$data = urlencode(serialize($array));

echo '<img src="graph.php?data='.$data.'">';


// then to receive it

$ydata = unserialize(stripslashes($_GET&#1111;'data']));
i decided not to use sessions because i wanted the image to be linkable, even if the url is a mile long :)
Post Reply