Jump to content

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 :)
Link to comment
https://forums.phpfreaks.com/topic/13563-pie-chart-generator/
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]
Link to comment
https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-52663
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]
Link to comment
https://forums.phpfreaks.com/topic/13563-pie-chart-generator/#findComment-55221
Share on other sites

Archived

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

×
×
  • Create New...

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.