Jump to content

Archived

This topic is now archived and is closed to further replies.

Skeleten Neteleks

Pie chart generator

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Check this site out,

http://www.maani.us/charts/index.php

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
All segments are exactly the same width of 45 degrees

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.