[SOLVED] Adding selective data to a pie chart

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
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

[SOLVED] Adding selective data to a pie chart

Post 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?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

hehe np
Post Reply