mishuk Posted February 13, 2007 Share Posted February 13, 2007 Hi. I found this pie chart script on here and am hoping to use it as the basis for what i need to achieve. However i tried to apply it to my stylesheet to make sure it worked and i have this error Warning: Cannot modify header information - headers already sent by (output started at... can anyone suggest how to rectify the problem <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Careers Tracking System - Year 9 Reports</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- @import url("style.css"); --> </style> </head> <body> <div id ="container"> </div> <div id ="menu"> </div> <div id ="content"> <?php $values = array(1, 1); // values from your db $im = imagecreate(450,250); $bg = imagecolorallocate($im, 0, 0, 0); $white = ImageColorAllocate ($im, 255, 255, 255); $colors = array( imagecolorallocate($im, 0xFF, 0, 0), //red imagecolorallocate($im, 0, 0xFF, 0), //green imagecolorallocate($im, 0, 0, 0xFF) //blue ); $s_angle = 0; // pie slice start angle $e_angle = 0; // pie slice end angle $total = array_sum($values); $k = count($values); $cx = 225; $cy = 125; // centre of the pie chart for ($i=0; $i<$k; $i++) { $a = $values[$i] / $total * 360; // angle for this slice $e_angle += $a; imagefilledarc($im, $cx, $cy, 180, 180, $s_angle, $e_angle, $colors[$i], IMG_ARC_PIE); $s_angle += $a; // start angle for next slice } ImageString($im, 4, 30, 50, 'Male', $white); ImageString($im, 4, 30, 70, 'Female', $white); header ('content-type: image/png'); imagepng($im); imagedestroy($im); ?> </div> </body> </html> Cheers Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 13, 2007 Share Posted February 13, 2007 Headers are automatically sent the moment you start outputting anything to the browser. Almost at the bottom of your code you have a statement trying to modify the header: header ('content-type: image/png'); Now look at your error message: Warning: Cannot modify header information - headers already sent Putting 2 and 2 together gives... Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted February 13, 2007 Share Posted February 13, 2007 You cannot create a image and echo html at the same time. You have to have the image creation code in an external file and then use the img HTML tag to grab the generated image. Like so: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Careers Tracking System - Year 9 Reports</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- @import url("style.css"); --> </style> </head> <body> <div id ="container"> </div> <div id ="menu"> </div> <div id ="content"> <img src="image.php"> </div> </body> </html> image.php <?php $values = array(1, 1); // values from your db $im = imagecreate(450,250); $bg = imagecolorallocate($im, 0, 0, 0); $white = ImageColorAllocate ($im, 255, 255, 255); $colors = array( imagecolorallocate($im, 0xFF, 0, 0), //red imagecolorallocate($im, 0, 0xFF, 0), //green imagecolorallocate($im, 0, 0, 0xFF) //blue ); $s_angle = 0; // pie slice start angle $e_angle = 0; // pie slice end angle $total = array_sum($values); $k = count($values); $cx = 225; $cy = 125; // centre of the pie chart for ($i=0; $i<$k; $i++) { $a = $values[$i] / $total * 360; // angle for this slice $e_angle += $a; imagefilledarc($im, $cx, $cy, 180, 180, $s_angle, $e_angle, $colors[$i], IMG_ARC_PIE); $s_angle += $a; // start angle for next slice } ImageString($im, 4, 30, 50, 'Male', $white); ImageString($im, 4, 30, 70, 'Female', $white); header ('content-type: image/png'); imagepng($im); imagedestroy($im); ?> Quote Link to comment Share on other sites More sharing options...
mishuk Posted February 14, 2007 Author Share Posted February 14, 2007 ah right. thanks very much Quote Link to comment 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.