Jump to content

variable handling/management


harleydude

Recommended Posts

I am using JPGraph to create some basic line graphs. According to the spec's i have, there can be anywhere from 1 line to 10 lines on a graph at a time depending on the SQL criteria being passed.

Now, in JPGraph, you define a line like this (truncated for simplicity):
[code]
// Create the first line
$p1 = new LinePlot($datay1);
$p1->SetColor("navy");
$graph->Add($p1);
[/code]

Note that the line is a standard variable name ($p1). To add another line you just rinse and repeat this code. NOW, since the number of lines is arbitrary, is there a way to pass a variable variable to the JPGraph and replace the $p1 with a more usable scoped variable?

I was looking for something like:
[code]
for($i=0;$i<sizeof($chartarray);$i++){
  $p=$("p".$i);
  $$p = new LinePlot($chartarray[$i]); // get list stored in $i position
  $$p->SetColor("navy");
  $graph->Add($$p);
}
[/code]
I just read some on variable variables but am not sure of how they work and this bit odf code is off the top of my head and is not tested. I will play with this some but need to know if the concept works and best way to impliment it.

Thanks  in advance,

HD
Link to comment
Share on other sites

That helps but the chart is blank...

I have an array ($dt) with the following data:
[code]
** > y dataArray
(
    [0] => Array
        (
            [0] => 1.00
            [1] => 1.00
            [2] => 1.00
            [3] => 1.00
            [4] => 1.00
        )

    [1] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 1.50
            [4] => 1.50
        )

    [2] => Array
        (
            [0] => 0
            [1] => 2.47
            [2] => 2.50
            [3] => 2.51
            [4] => 2.51
        )
[/code]
Here is what I have for each line of the graph:
[code]
$graph = new Graph(350,250,"auto");   
$graph->SetScale("textlin");
for($i=0;$i<sizeof($dt);$i++){
$p="p".$i;
$$p = new LinePlot($dt[$i]); // get list stored in $i position
$graph->Add($$p);
}
[/code]

image outputs empty indicating that jpgraph does not like the data.

I have also tried this by setting $i=0 and commenting out the for loop with no success either. JPGraph does not like the $p="p".$i; varaible name.

Can anyone offer help or ideas on how to fix the above code snippet?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.