Page 1 of 1

[SOLVED] Adding selective data to a pie chart

Posted: Fri Nov 21, 2003 5:34 pm
by infolock
I have the following array (for a pie graph) :

Code: Select all

<?php

$data = array(''.$Net.''=> $Net_Value, ''.$Moz.'' => $Moz_Value,''.$NSP.'' => $NSP_Value, ''.$WMP9.'' => $WMP9_Value,''.$WMP8.'' => $WMP8_Value, ''.$WMP7.'' => $WMP7_Value, ''.$IE6.'' => $IE6_Value, ''.$IE5.'' => $IE5_Value);

?>

Now, if All of these values are populated with a value, then that's fine. But if even 1 of them doesn't have a value, the pie graph just dies because it can't figure out the %'s to use with a null value...

so, i'm trying to write an if else statement that can handle it, only after doing the math, it's gonna be like 100,000 some odd possibilities lol..

anyone have a suggestion?

Posted: Fri Nov 21, 2003 6:46 pm
by infolock
i'm thinking this is gonna have to be down by converting the arrays to scalar variables an using the extract() , but we'll see.

Posted: Fri Nov 21, 2003 7:01 pm
by m3mn0n
Maybe an if statement before the image processing that will set the value to 0 (thus no piece of the pie) if it's null? Have you tried that already?

Posted: Fri Nov 21, 2003 7:28 pm
by infolock
well, see that's the thing. it takes whatever is passed from the $data array and calculates the size and number of pies to graph.

since the data will varry from log report to log report, there is no real way to determine which values to put into the $data array ( thus why i entered them all ).

see, i need to figure out a method to where i can assign $data with those variables that I have in it, but ONLY the variables that have values greater then 0.

so, WMP8 is actually Windows Media Player 8, and the WMPS_Found is # of occurances in my database that Windows Media player 8 was found. if it was found 8 times, then WMPS_Found = 8 and is places into the graphing function.


so, i need to say if WMP8_Found = 0, skip this variable, and check to see if the next variable can be placed in the data array.

edit :

ok, so i think i understand waht you are saying.

what i can do then, is put each variable into a temporary array, but only the ones that have values greater then 0. then i could use the conversion for arrays to scalar variables on the fly, and extract them into the $data array.

this will be very interesting to figure out, because at least now i have an idea of what i'm doing and can probably get this done in a little bit. thanks sami

Posted: Fri Nov 21, 2003 8:19 pm
by m3mn0n
np. You say this is from a database eh? How about eliminating all the empty values at the root, with simply adding WHERE whater_value>0 within your statement.

Then (i think) it would be a matter of making multiple arrays to process the code if one of the values is 0.

eg.

Code: Select all

<?php
if (!$Net_Value)
{
$data = array(''.$Moz.'' => $Moz_Value,''.$NSP.'' => $NSP_Value, ''.$WMP9.'' => $WMP9_Value,''.$WMP8.'' => $WMP8_Value, ''.$WMP7.'' => $WMP7_Value, ''.$IE6.'' => $IE6_Value, ''.$IE5.'' => $IE5_Value); 
} else {
$data = array(''.$Net.''=> $Net_Value, ''.$Moz.'' => $Moz_Value,''.$NSP.'' => $NSP_Value, ''.$WMP9.'' => $WMP9_Value,''.$WMP8.'' => $WMP8_Value, ''.$WMP7.'' => $WMP7_Value, ''.$IE6.'' => $IE6_Value, ''.$IE5.'' => $IE5_Value); 

}
?>
there probably a better way to do it but if my understanding of this is right, i think that would work.

Posted: Fri Nov 21, 2003 8:55 pm
by infolock
as you probably would have guessed, i figured out the problem... i was dividing the value by 200, so if the value of a variable was 0, then i was getting the error. sheesh, just had to put a simple "else $myvar = 0; " clause in there, and it prints it out nicely.. lol. thanks for the help though sami

Posted: Fri Nov 21, 2003 10:20 pm
by m3mn0n
hehe np