Forum Moderators: coopster

Message Too Old, No Replies

Conditions determining the output

         

PRosales

6:25 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



I have 5 arrays that I am passing to JPGraph. I am successfull with graphing 1 or all 5 arrays, but I am trying to graph the selected arrays as requested. I am of the impression that constructing IF conditions would do the trick, but I have not been successfull in utilizing them. I simply wish that if the array is available pass it, if it isn't then move on to the next array and determine if it is available. Here is what I have so far:

if ($select!= 'nodes_available')
{
// Create the first line
$p1 = new LinePlot($data1y);
$p1->mark->SetType(MARK_FILLEDCIRCLE);
$p1->mark->SetFillColor("red");
$p1->mark->SetWidth(4);
$p1->SetColor("red");
$p1->SetCenter();
$p1->SetLegend("Nodes Available");
$graph->Add($p1);
}
if ($select!= 'nodes_busy')
{
// Create the second line
$p2 = new LinePlot($data2y);
$p2->mark->SetType(MARK_STAR);
$p2->mark->SetFillColor("green");
$p2->mark->SetWidth(4);
$p2->SetColor("green");
$p2->SetCenter();
$p2->SetLegend("Nodes Busy");
$graph->Add($p2);
}

Please help.

mcibor

9:53 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I understand that $data1y, 2y.. are the arrays?

you can loop through them:

$mark = array("", "FILLEDCIRCLE", "STAR", "BLA", "BALL", "BLAA")
$color = array("", "red", "green", "magenta", "black", "cyan");
$legend = array("", "Nodes Avaliable", "Nodes Busy", "bla", "alb", "bal");
for($i = 1; $i <= 5; $i++){
if($data = ${"data$i"."y"}){

$p = new LinePlot($data);
$p->mark->SetType(MARK_$mark[$i]);
$p->mark->SetFillColor($color[$i]);
$p->mark->SetWidth(4);
$p->SetColor($color[$i]);
$p->SetCenter();
$p->SetLegend($legend[$i]);
$graph->Add($p);
}}

mcibor

9:53 pm on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




The arrays containing mark, color and legend have first value empty, because first value is $color[0], and you start your data from 1 (data1y).
${"bla"} means the variable is really $bla. Therefore for $i = 1 you get ${"data$i"."y"} is ${"data1"."y"} is ${"data1y"} is $data1y
If MARK_... won't work, then put it whole into an array. Maybe even without the " "
Hope this helps
Michal Cibor

PS the empty are not processed as you have if there. but if it doesn't then correct the if to if(isset(${...}))