stelthius Posted July 22, 2008 Share Posted July 22, 2008 Hi guys i use a script to show me the quota a user is using and it shows a pie chart Example - instead of it being the pie chart i want it to show like this exampl below Can anyone help me with this please also if you need to see code just let me know and ill show you what i use thanks and regards Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/ Share on other sites More sharing options...
.josh Posted July 22, 2008 Share Posted July 22, 2008 Are you using some special library or 3rd party script to generate that? Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-596975 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 to generate what the pie chart or the graph ? Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597026 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 gdlibrary was used to develop the graphs, you need to look into GD deeply to discover how to make charts. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597029 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 im pretty sure GD wasnt used as i dont have GD installed mate :| Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597036 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 I'm 100% sure GD was used because php can not easily generate pictures without it Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597037 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 well iknow i dont have GD installed so it musnt be, can you recomend any good tutorials or places to start reading mate ? as i need to work this one out and pretty fast too lol Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597045 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 well then u ain't making the graphs on your server try googles php graphing and u need GD installed Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597049 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 the graph is being made on the server, it calls nothing from the out side world, Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597050 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 show us how its made then cause your lying about something here Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597052 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 excuse me ? why would i be telling lies about how the script works that simply just doesnt make sense, i do NOT have GD installed and the script does NOT call any out of the server functions doesnt call images from out of the box either, please dont call me a liar for explaining what the script does. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597054 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 then show the code. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597058 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 fair enough, you still have no rights to call me a liar, <?php class userQuota { var $qType; // output type var $qQuota; // quota value var $qUsed; // used value var $qUser; // input user name var $gWidth; // width of pie chart var $gHeight; // height of pie chart (determined by width) var $g3DHeight; // do we want a 3D look or not var $gLegend; // display the legend or not var $gQuotaColour; // colour of quota var $gUsedColour; // colour of used space var $gBackColour; // colour of the background var $gTextColour; // colour of the legend text var $gCentreUsed; // centre the 'used' wedge to bottom of pie function userQuota($quota, $used, $username = '') { $this->qUser = $username; $this->setOutputImage(); $this->setImageProperties(); $this->qQuota = $quota; $this->qUsed = $used; $this->oPercent = ($this->qUsed / (!$this->qQuota ? 1 : $this->qQuota)) * 100; $this->qUser = $username; if ($this->oPercent > 100) { $this->oPercent = 100; } } function setOutputText() { $this->qType = 0; } function setOutputImage() { $this->qType = 1; } function setImageProperties($width = 150, $threeD = TRUE, $legend = TRUE, $centre = TRUE, $qc = 'DDDDDD', $uc = 'ED1C24', $bc = 'FFFFFF', $tc = '000000') { $this->gWidth = (!$width ? 150 : $width); if ($threeD) { $this->gHeight = $width/2; $this->g3DHeight = $width/10; } else { $this->gHeight = $width; $this->g3DHeight = 0; } $this->gLegend = ($legend == TRUE ? TRUE : FALSE); $this->gCentreUsed = ($centre == TRUE ? TRUE : FALSE); $this->gQuotaColour = $this->_htmlHexToBinArray($qc); $this->gUsedColour = $this->_htmlHexToBinArray($uc); $this->gBackColour = $this->_htmlHexToBinArray($bc); $this->gTextColour = $this->_htmlHexToBinArray($tc); } function displayQuota() { ($this->qType == 0) ? $this->_displayText() : $this->_displayImage(); } function _htmlHexToBinArray($hex) { for ($i=0; $i<3; $i++) { $foo = substr($hex, 2*$i, 2); $rgb[$i] = 16 * hexdec(substr($foo, 0, 1)) + hexdec(substr($foo, 1, 1)); } return $rgb; } function _displayText() { if ($this->qUser) echo 'The quota for ', $this->qUser; else echo 'Your quota'; echo ' is ', $this->_formatSize($this->qQuota), ' and ', ($this->qUser ? 'they' : 'you'), ' have used ', $this->_formatSize($this->qUsed), ' (', number_format($this->oPercent, 2), '%) of it.'; } function _displayImage() { // the graph variables $sStart = $this->g3DHeight * 2; $wStart = $this->gWidth * 2; $hStart = $this->gHeight * 2; if ($this->qUsed >= $this->qQuota) $usedPercent = 359; else $usedPercent = $this->oPercent * 3.6; if ($this->gCentreUsed) { $sWedge = (int)(90 - ($usedPercent / 2)); if ($sWedge < 0) $sWedge += 360; $mWedge = (int)(90 + ($usedPercent / 2)); $mWedge = ($mWedge == 90 ? 91 : $mWedge); $eWedge = (int)$sWedge; } else { $sWedge = 0; $mWedge = (int)($usedPercent ? $usedPercent : 1); $eWedge = 360; } $im = @ImageCreateTrueColor($wStart, $hStart + $sStart); if ($im) { $cBg = ImageColorAllocate($im, $this->gBackColour[0], $this->gBackColour[1], $this->gBackColour[2]); $cUsed = ImageColorAllocate($im, $this->gUsedColour[0], $this->gUsedColour[1], $this->gUsedColour[2]); $cQuota = ImageColorAllocate($im, $this->gQuotaColour[0], $this->gQuotaColour[1], $this->gQuotaColour[2]); ImageFill($im, 0, 0, $cBg); if ($this->g3DHeight) { $qDarkArray = $this->gQuotaColour; for ($i=0; $i<3; $i++) { ($qDarkArray[$i] > 99) ? $qDarkArray[$i] -= 100 : $qDarkArray[$i] = 0; } $uDarkArray = $this->gUsedColour; for ($i=0; $i<3; $i++) { ($uDarkArray[$i] > 99) ? $uDarkArray[$i] -= 100 : $uDarkArray[$i] = 0; } $cQuotaDark = ImageColorAllocate($im, $qDarkArray[0], $qDarkArray[1], $qDarkArray[2]); $cUsedDark = ImageColorAllocate($im, $uDarkArray[0], $uDarkArray[1], $uDarkArray[2]); $shadow_start = ($hStart/2) + $sStart; $shadow_end = $hStart/2; for ($i=$shadow_start - 1; $i>$shadow_end; $i--) { ImageFilledArc($im, ($wStart/2), $i, $wStart, $hStart, $sWedge, $mWedge, $cUsedDark, IMG_ARC_PIE); ImageFilledArc($im, ($wStart/2), $i, $wStart, $hStart, $mWedge, $eWedge, $cQuotaDark, IMG_ARC_PIE); } } ImageFilledArc($im, ($wStart/2), ($hStart/2), $wStart, $hStart, $sWedge, $mWedge, $cUsed, IMG_ARC_PIE); ImageFilledArc($im, ($wStart/2), ($hStart/2), $wStart, $hStart, $mWedge, $eWedge, $cQuota, IMG_ARC_PIE); if ($this->gLegend) { $lHeight = $lWidth = 0; $spacer = 10; $qText[0] = 'Quota: ' . $this->_formatSize($this->qQuota); if ($this->qUser) $qText[1] = ' (' . $this->qUser . ')'; else $qText[1] = ''; $uText[0] = 'Used : ' . $this->_formatSize($this->qUsed); $uText[1] = ' (' . number_format($this->oPercent,2) . '%)'; $lHeight = (ImageFontHeight(2) * ($qText[1] == '' ? 3 : 4)) + $spacer; $qMax = (strlen($qText[0]) > strlen($qText[1])) ? strlen($qText[0]) : strlen($qText[1]); $uMax = (strlen($uText[0]) > strlen($uText[1])) ? strlen($uText[0]) : strlen($uText[1]); $tMax = ($qMax > $uMax ? $qMax : $uMax); $lWidth = ($tMax * ImageFontWidth(2)) + $spacer + ImageFontHeight(2); $lim = ImageCreateTrueColor($lWidth, $lHeight); ImageFill($lim, 0, 0, $cBg); $cText = ImageColorAllocate($lim, $this->gTextColour[0], $this->gTextColour[1], $this->gTextColour[2]); $lx = 0; $ly = 0; ImageFilledRectangle($lim, $lx, $ly, ($lx + ImageFontHeight(2)), ($ly + ImageFontHeight(2)), $cQuota); ImageString($lim, 2, ($lx + ImageFontHeight(2) + $spacer), $ly, $qText[0], $cText); if ($qText[1] != '') { $ly += ImageFontHeight(2); ImageString($lim, 2, ($lx + ImageFontHeight(2) + $spacer), $ly, $qText[1], $cText); } $ly += ($spacer + ImageFontHeight(2)); ImageFilledRectangle($lim, $lx, $ly, ($lx + ImageFontHeight(2)), ($ly + ImageFontHeight(2)), $cUsed); ImageString($lim, 2, ($lx + ImageFontHeight(2) + $spacer), $ly, $uText[0], $cText); $ly += ImageFontHeight(2); ImageString($lim, 2, ($lx + ImageFontHeight(2) + $spacer), $ly, $uText[1], $cText); $gsx = ImageSX($im); $gsy = ImageSY($im); $lsx = ImageSX($lim); $lsy = ImageSY($lim); $gnx = ($gsx >> 1); $gny = ($gsy >> 1); $fx = ($gnx > $lsx) ? $gnx : $lsx; $fy = $gny + $lsy + ($spacer * 2); $final = ImageCreateTrueColor($fx, $fy); ImageFill($final, 0, 0, $cBg); ImageCopyResampled($final, $im, (($fx/2)-($gnx/2)), 0, 0, 0, $gnx, $gny, $gsx, $gsy); ImageCopyResampled($final, $lim, (($fx/2)-($lsx/2)), $gny + ($spacer * 2), 0, 0, $lsx, $lsy, $lsx, $lsy); ImageDestroy($lim); } else { $sx = ImageSX($im); $sy = ImageSY($im); $nx = ($sx>>1); $ny = ($sy>>1); $final = ImageCreateTrueColor($nx, $ny); ImageCopyResampled($final, $im, 0, 0, 0, 0, $nx, $ny, $sx, $sy); } header("Content-type: image/jpeg"); ImageJPEG($final, NULL, 100); ImageDestroy($im); ImageDestroy($final); } } function _formatSize($size = 0) { if ($size >= 1073741824) $size = round($size/1073741824*100)/100 . " Gb"; else if ($size >= 1048576) $size = round($size/1048576*100)/100 . " Mb"; else if ($size >= 1024) $size = round($size/1024*100)/100 . " kb"; else $size = $size . " bytes"; return $size; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597060 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 Like I said you are a lier that class has in it $im = @ImageCreateTrueColor($wStart, $hStart + $sStart); http://us3.php.net/image%20create%20true%20color Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597062 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 ok ill say this slower, my box does not have GD installed, i set up my box about 4 hours ago, i have not installed GD no-one has access to my box, unless CentOS 5.2 has GD in it then it isnt installed Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597063 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 well then your classes for generating graphs isn't running on your box??? Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597069 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 ok im gonna end this here as its obvious something isnt how it should be plain and simple i dont have GD installed, the script is running on my box, what more can i say its running it works, all i want to do is change the way it shows the data, sorry for bothering you! Rick, Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597074 Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 Hey guys no need to fight. stelthius isn't necessarily lying; as he said, what's the point in lying about it? He may simply not know and he's just assuming it's not installed because he didn't go install it. But nonetheless, stelthius, the following: ImageCreateTrueColor ImageColorAllocate ImageFill ImageFilledArc ImageFilledRectangle ImageFontHeight ImageString ImageSX ImageSY ImageCopyResampled ImageDestroy ImageJPEG are in your script. Those are all functions of the GD library, so you somehow do indeed have the GD library installed and enabled on your system. You had to have installed apache/php or maybe a package like WAMP or XAMPP or something, maybe it came with the bundle. Who knows? But the bottom line is that you do have it installed, because your script wouldn't run without it. Check out what the GD library has to offer, in the way of doing what you want. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597079 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 Thanks for your reply Crayon, as i was saying tho i installed CentOS 5 on my box around 4 - 5 hours ago so unless its in there then im clueless as no one else has access to the box lol wierd :/ Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597090 Share on other sites More sharing options...
tibberous Posted July 23, 2008 Share Posted July 23, 2008 1) You don't have to install GD to have it, it's like the yahoo toolbar That said, it is a GD function which means you are probably running GD, and you can find out for sure by using the phpinfo() function. 2) You don't have to have GD to make an image on the server. There are tons of other libraries, and you don't even need a library, because you could run something like Image Magick command line and then route the image. 3) In a world where people are generally very tactful, it's sometimes funny to see something blatantly hostile and completely unprovoked. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597095 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 1) You don't have to install GD to have it, it's like the yahoo toolbar That said, it is a GD function which means you are probably running GD, and you can find out for sure by using the phpinfo() function. 2) You don't have to have GD to make an image on the server. There are tons of other libraries, and you don't even need a library, because you could run something like Image Magick command line and then route the image. 3) In a world where people are generally very tactful, it's sometimes funny to see something blatantly hostile and completely unprovoked. 1) Yes you do it could be part of the installation you used (such as wamp xamp uniform server) and yahoo toolbar needs to be installed. 2) It isn't image magick because of the functions being used 3) I am not hostile I just hate when people are stubborn about something and they don't even take the time to check if a prediction is correct. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597097 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 well one thing i can say for sure im just looking for a way to make the quota show the second way rather than the pie chart lol Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597098 Share on other sites More sharing options...
cooldude832 Posted July 23, 2008 Share Posted July 23, 2008 that being said I go back to my original statement that you need to use GD to generate the images as needed. Since this class looks like it wasn't written by you then this will be a challenge to do ti without any help. I suggest you google php graphing with GD tutorials as I suggested 20 post ago. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597099 Share on other sites More sharing options...
DarkWater Posted July 23, 2008 Share Posted July 23, 2008 Let's settle this once and for all. Stelthius, no one touched your box, it's just the PHP has GD bundled already. =/ And it's not so easy to magically present data in a different fashion. You're going to need the background image, first of all, and a "circle" image that you will need to calculate the location of based on percentages. Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597101 Share on other sites More sharing options...
stelthius Posted July 23, 2008 Author Share Posted July 23, 2008 yeah i have all the images i made them earlier in hope that this was going to be an easy task and cooldude i did take notice of you and i did google what you suggested Quote Link to comment https://forums.phpfreaks.com/topic/116090-php-pie-chart/#findComment-597102 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.