Page 1 of 1

JPGraph and Arrays

Posted: Thu Jan 13, 2005 6:46 pm
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.

Posted: Thu Jan 13, 2005 6:52 pm
by feyd
look into serialize() or join() or some of the other array/variable functions.. because echoing and array variable just prints "Array"

Posted: Thu Jan 13, 2005 7:41 pm
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.

Posted: Thu Jan 13, 2005 9:13 pm
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 :)