Does anyone know what tv.com uses to create the pie chart seen in the following link:
http://www.tv.com/misc/image.php?itype=2&idata=5021:3960:1113:283:294&icolor=10:9:8:7:1

You can manipulate this chart by changing the "idata" and "icolor" fields!

I need to create charts and graphs from complex mySQL queries and cannot find one that works well. I have been playing with "PHP/SWF Charts" from http://www.maani.us/ but keep running into timeout issues. Besides, I would like to avoid using flash.

I am currently looking at "ChartDirector" at http://www.advsofteng.com/ and it looks more robust that PHP/SWF.

Anyone have a better recommendation? I don't know how to manually create graphics using GD and I a newbie to PHP so, I want to stick with controls that can be downloaded/purchased and data passed to.

Thanks,
Charles

    That's pretty cool - I will check this out. The graphs don't seem to be as polished but, for my needs that is not an issue.

    Any others?

    Thanks,
    Charles

      22 days later
      jchaven wrote:

      Does anyone know what tv.com uses to create the pie chart seen in the following link:
      http://www.tv.com/misc/image.php?itype=2&idata=5021:3960:1113:283:294&icolor=10:9:8:7:1

      You can manipulate this chart by changing the "idata" and "icolor" fields!

      I have a feeling it might be http://www.advsofteng.com/gallery.html

      I'm also looking for some very flashy/pretty charting software that uses PHP+GD without requiring Flash. I'll keep you posted if I find something better.

      Matt

        I have written this code using [man]imagefilledarc[/man] and you can easily make piecharts that look like that with it.

        <?
        $Randomized = rand(1,20);
        for($i=0;$i<=$Randomized;$i++){$data[$i]=rand(2,20);};//full array with garbage.
        $imgx='200';$imgy='200';//Set Image Size. ImageX,ImageY
        $cx = '100';$cy ='50'; //Set Pie Postition. CenterX,CenterY
        $sx = '200';$sy='100';$sz ='20';// Set Size-dimensions. SizeX,SizeY,SizeZ
        
        $data_sum = array_sum($data);
        //convert to angles.
        for($i=0;$i<=$Randomized;$i++){
           $angle[$i] = (($data[$i] / $data_sum) * 360);
           $angle_sum[$i] = array_sum($angle);
        };
        $im  = imagecreate ($imgx,$imgy);
        $background = imagecolorallocate($im, 255, 255, 255);
        //Random colors.
        for($i=0;$i<=$Randomized;$i++){
           $r=rand(100,255);$g=rand(100,255);$b=rand(100,255);   
        $colors[$i] = imagecolorallocate($im,$r,$g,$b); $colord[$i] = imagecolorallocate($im,($r/2),($g/2),($b/2)); } //3D effect. for($i=0;$z<=$sz;$z++){ for($i=0;$i<=$Randomized;$i++){ imagefilledarc($im,$cx,($cy+$sz)-$z,$sx,$sy,$angle_sum[$i-1] ,$angle_sum[$i],$colord[$i],IMG_ARC_PIE); }; }; //Top pie. for($i=0;$i<=$Randomized;$i++){ imagefilledarc($im,$cx,$cy,$sx,$sy,$angle_sum[$i-1] ,$angle_sum[$i], $colors[$i], IMG_ARC_PIE); }; //Output. header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?>

        i wrote this a while ago but it should suit your needs

          6 days later

          Here's a modified version of _theworks's code. My example uses TV.com's way of grabbing the pie's size and colors. I also added a small piece of code to smooth everything out. I hope this helps you out...

          <?
          // image data
          $_owidth  = 150;
          $_oheight = 150;
          $_pdepth  = 50;
          // color palette
          $_pallete  = array(
          	array(51, 204, 0),  // 0: dark green
          	array(102, 255, 0), // 1: light green
          	array(153, 255, 0), // 2: lighter green
          	array(204, 255, 0), // 3: yellowish green
          	array(255, 255, 0), // 4: yellow
          	array(255, 204, 0), // 5: opaque orange
          	array(255, 153, 0), // 6: orange
          	array(255, 102, 0), // 7: opaque red
          	array(204, 51, 0),  // 8: red
          	array(204, 0, 0)    // 9: dark red
          );
          // dynamic image data
          $_rwidth  = $_owidth * 2;
          $_rheight = $_oheight * 2;
          $_pwidth  = $_rwidth - $_pdepth;
          $_pheight = $_rheight - ($_pdepth * 3);
          $_xcenter = $_rwidth / 2;
          $_ycenter = ($_rheight - $_pdepth) / 2;
          // data validation
          if (isset($_GET['idata']) && trim($_GET['idata']) !== "") {
          	$_data     = explode(":", $_GET['idata']);
          	$_data_sum = array_sum($_data);
          	$_pieces   = count($_data);
          } else {
          	echo "error: missing idata variable...";
          	exit(1);
          }
          if (isset($_GET['icolor']) && trim($_GET['icolor']) !== "") {
          	$_clist  = explode(":", $_GET['icolor']);
          	$_ccount = count($_clist);
          	if ($_ccount < $_pieces) {
          		echo "error: invalid number of colors";
          		exit(1);
          	} else {
          		for ($i=0; $i<$_ccount; $i++) {
          			$_colors[$i] = $_pallete[$_clist[$i]];
          		}
          	}
          } else {
          	$_colors = $_pallete;
          }
          // convert values to angles
          for ($i=0; $i<$_pieces; $i++) {
          	$_angle[$i]     = (($_data[$i] / $_data_sum) * 360);
          	$_angle_sum[$i] = array_sum($_angle);
          }
          // create render image
          $_image = @imagecreate ($_rwidth, $_rheight);
          $_black = imagecolorallocate($_image, 0, 0, 0);
          $_white = imagecolorallocate($_image, 255, 255, 255);
          imagefill($_image, 0, 0, $_white);
          // create random colors
          for ($i=0; $i<$_pieces; $i++) {
          	$_scolor[$i] = imagecolorallocate($_image, $_colors[$i][0], $_colors[$i][1], $_colors[$i][2]);
          	$_dcolor[$i] = imagecolorallocate($_image, ($_colors[$i][0]/1.5), ($_colors[$i][1]/1.5), ($_colors[$i][2]/1.5));
          }
          // create 3d effect
          for ($z=0; $z<$_pdepth; $z++) {
          	for ($i=0; $i<$_pieces; $i++) {
          		imagefilledarc($_image, $_xcenter, ($_ycenter+$_pdepth)-$z, $_pwidth, $_pheight, $_angle_sum[$i-1], $_angle_sum[$i], $_dcolor[$i], IMG_ARC_PIE);
          	}
          }
          // create surface pie
          for ($i=0; $i<$_pieces; $i++) {
          	imagefilledarc($_image, $_xcenter, $_ycenter, $_pwidth, $_pheight, $_angle_sum[$i-1], $_angle_sum[$i], $_scolor[$i], IMG_ARC_PIE);
          }
          // resample image
          $_fimage = @imagecreatetruecolor($_owidth, $_oheight);
          imagecopyresampled($_fimage, $_image, 0, 0, 0, 0, $_owidth, $_oheight, $_rwidth, $_rheight);
          // output
          header('Content-type: image/gif');
          imagegif($_fimage);
          imagedestroy($_fimage);
          imagedestroy($_image);
          ?>
          

          Use as follows:
          filename.php?idata=800:400:420:560:380:1000&icolor=9:4:3:2:1:0

          You can also use it without the icolor variable.

          😃

            nice to see it was of use to someone...

              Write a Reply...