Jump to content


Photo

Pie chart generator


  • Please log in to reply
9 replies to this topic

#1 Skeleten Neteleks

Skeleten Neteleks
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 03 July 2006 - 04:39 PM

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

#2 maxim

maxim
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 03 July 2006 - 07:46 PM

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

#3 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 03 July 2006 - 07:51 PM

Check this site out,

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

NoGray.com


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 03 July 2006 - 09:14 PM

save as oddpie.php
<?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);
?>

Run this
<?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>';
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Skeleten Neteleks

Skeleten Neteleks
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 08 July 2006 - 05:36 PM

Thank you very much, I am sorry for the delay in responding. I will let you know how it goes.

#6 Skeleten Neteleks

Skeleten Neteleks
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 08 July 2006 - 11:21 PM

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

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 July 2006 - 09:45 AM

All segments are exactly the same width of 45 degrees
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 Skeleten Neteleks

Skeleten Neteleks
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 09 July 2006 - 03:35 PM

my eyes play tricks on me! thank you

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 09 July 2006 - 05:04 PM

if it helps, this version draws the radials.

<?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);
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#10 Skeleten Neteleks

Skeleten Neteleks
  • Members
  • PipPipPip
  • Advanced Member
  • 51 posts

Posted 09 July 2006 - 06:37 PM

brill, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users