Skeleten Neteleks Posted July 3, 2006 Share Posted July 3, 2006 Hi, I have been looking for a very specific pie chart generator.There would be 8 drop down boxes that a visitor would select from, each containing numbers from 0 to 10.When submitting the form, a image of a pie chart is generated based on those results.I have found scripts that do this, but not quite how I want the pie chart to be displayed.The pie chart should not have an outer ring. The segments should be equal width and the value of each segment should be represented by the height of that particular segment.So a segment value of 10 would be the highest from the central point, and 5 would be half way and 0 would be no segment at all.The segments should also have different colours.Could anyome point me in the direction of this script (if it exists)? many many thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/ Share on other sites More sharing options...
maxim Posted July 3, 2006 Share Posted July 3, 2006 i dont know of any scripts. but if its something custom then looks into PHP's GD extention. It has the abilty to do what you want. you will need to read up on GD, so hit up google Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-52617 Share on other sites More sharing options...
nogray Posted July 3, 2006 Share Posted July 3, 2006 Check this site out,http://www.maani.us/charts/index.php Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-52621 Share on other sites More sharing options...
Barand Posted July 3, 2006 Share Posted July 3, 2006 save as oddpie.php[code]<?php $vals = explode('|',$_GET['vals']); $image = imagecreate(420,420); $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $a = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); $b = imagecolorallocate($image, 0x90, 0x90, 0x90); $c = imagecolorallocate($image, 0x00, 0x00, 0xFF); $d = imagecolorallocate($image, 0x00, 0x00, 0x90); $e = imagecolorallocate($image, 0xFF, 0x00, 0x00); $f = imagecolorallocate($image, 0x90, 0x00, 0x00); $g = imagecolorallocate($image, 0x00, 0xFF, 0x00); $h = imagecolorallocate($image, 0x00, 0x90, 0x00); $colArray = array($a,$b,$c,$d,$e,$f,$g,$h); $cx = $cy = 210; $theta = 0; $col = 0; foreach ($vals as $val) { $r = $val*200 / 10; imagefilledarc($image,$cx, $cy, $r, $r, $theta, $theta+45, $colArray[$col], IMG_ARC_PIE); $theta += 45; $col++; }header('Content-type: image/png');imagepng($image);imagedestroy($image);?>[/code]Run this[code]<?php if (isset($_GET['submit'])) { $vals = join ('|', $_GET['pieval']); echo "<IMG src=oddpie.php?vals=$vals>" ; echo '<hr>'; }echo '<FORM>';for ($s=0; $s<8; $s++) { echo '<SELECT name="pieval[]">'; for ($i=0; $i<=10; $i++) { echo "<option value='$i'>$i</option>"; } echo '</select>';}echo '<input type="submit" name="submit" value="Submit">';echo '</form>';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-52663 Share on other sites More sharing options...
Skeleten Neteleks Posted July 8, 2006 Author Share Posted July 8, 2006 Thank you very much, I am sorry for the delay in responding. I will let you know how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-54844 Share on other sites More sharing options...
Skeleten Neteleks Posted July 8, 2006 Author Share Posted July 8, 2006 Hi thanks, I tried it. The segments with a higher value seem to be wider than the smaller ones. I was looking for a set width for each segment. No worries anyway, thanks for your help. :) Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-54976 Share on other sites More sharing options...
Barand Posted July 9, 2006 Share Posted July 9, 2006 All segments are exactly the same width of 45 degrees Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-55056 Share on other sites More sharing options...
Skeleten Neteleks Posted July 9, 2006 Author Share Posted July 9, 2006 my eyes play tricks on me! thank you Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-55188 Share on other sites More sharing options...
Barand Posted July 9, 2006 Share Posted July 9, 2006 if it helps, this version draws the radials.[code]<?php $vals = explode('|',$_GET['vals']); $image = imagecreate(420,420); $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $a = imagecolorallocate($image, 0xC0, 0xC0, 0xC0); $b = imagecolorallocate($image, 0x90, 0x90, 0x90); $c = imagecolorallocate($image, 0x00, 0x00, 0xFF); $d = imagecolorallocate($image, 0x00, 0x00, 0x90); $e = imagecolorallocate($image, 0xFF, 0x00, 0x00); $f = imagecolorallocate($image, 0x90, 0x00, 0x00); $g = imagecolorallocate($image, 0x00, 0xFF, 0x00); $h = imagecolorallocate($image, 0x00, 0x90, 0x00); $blk = imagecolorallocate($image, 0x00, 0x00, 0x00); $colArray = array($a,$b,$c,$d,$e,$f,$g,$h); $cx = $cy = 210; $alpha = 0; $col = 0; foreach ($vals as $val) { $r = $val*40; $theta = 45; imagefilledarc($image,$cx, $cy, $r, $r, $alpha, $theta+$alpha, $colArray[$col], IMG_ARC_PIE); $alpha += $theta; $col++; } for ($alpha=0; $alpha<360; $alpha += 45) { $alpharad = deg2rad($alpha); imageline($image,$cx,$cy, $cx+200*cos($alpharad), $cy+200*sin($alpharad),$blk); for ($i=40; $i<=400; $i+=40) { imagefilledarc($image,$cx, $cy, $i, $i, $alpha-2, $alpha+2, $blk, IMG_ARC_NOFILL); } }header('Content-type: image/png');imagepng($image);imagedestroy($image);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-55221 Share on other sites More sharing options...
Skeleten Neteleks Posted July 9, 2006 Author Share Posted July 9, 2006 brill, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-55238 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.