[SOLVED] Drawing with php
Moderator: General Moderators
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
[SOLVED] Drawing with php
I have an array with around 70 ($hist) values in it, how can i graphically represent this as if it is a line graph where all of the lines are next to one another with no gaps in between. I cant seem to get any of the draw functions properly to achieve this.
Thanks
RJ
Thanks
RJ
Last edited by rubberjohn on Wed Apr 06, 2005 10:14 am, edited 1 time in total.
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
before i go can you tell me why i am getting this when i try and use the drawing functions
Code: Select all
‰PNG IHDRÈ–æ²/Š PLTEÈÈÈéї––ÿB „„_IDATxœí™±n„0 †)^ÚåNrÞÇ‘¸ÝHäO}Ân 4w®Úþ— ÇŸý;ˆpý…$°LW¸‘-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
you mean this
Code: Select all
header ("Content-type: image/png");- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
here it is, by the way this isn't the code that i originally wrote, i got this off the web just to try an see if the problem was my code or something else:
which gives me:
Code: Select all
<?php
header ("Content-type: image/png");
#$histogram = imagecreate(100,100);
#for ($v=0; $v>=count($hist); $v++){
#imageline($histogram, 5, 5, 5, 5);
#echo "THIS IS IN THE LOOP" . $v;
#}
#imageline($histogram, 5, 5, 5, 5, 0);
#imagejpeg($histogram);
#imagedestroy($histogram);
/* We need this in order to return a picture */
$graph_data = array(
"question" => "Are you addicted to PHP ?" ,
"yes" => 82 ,
"no" => 18
);
/* Create the images */
$im = ImageCreate(200,150) or die("could not create image !! <br>");
/* allocate the colors */
$background_color = ImageColorAllocate ($im, 200, 200, 200);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
$bar_color = ImageColorAllocate ($im, 0, 0, 0);
$bar_color_fill = ImageColorAllocate ($im, 150, 150, 255);
/* draw some text .. */
ImageFill ($im,1,1,$background_color);
ImageString ($im, 3, 5, 5, $graph_data["question"], $text_color);
ImageString ($im, 2, 30, 130, "yes: ".$graph_data["yes"]."%" , $text_color);
ImageString ($im, 2, 110, 130, "no: ".$graph_data["no"]."%" , $text_color);
/* draw the bars */
ImageRectangle ($im, 30, 120 - $graph_data["yes"],50,120 ,$bar_color);
if($graph_data["yes"] > 2) { #so we won't fill the bg of the image ...
ImageFill ($im,31,119,$bar_color_fill);
}
ImageRectangle ($im, 110, 120 - $graph_data["no"],130,120 ,$bar_color);
if($graph_data["yes"] > 2) {
ImageFill ($im,111,119,$bar_color_fill);
}
/* returm image data */
ImagePng ($im);
?>Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at /home/ftpserver/www/homepage/student/engjbarn/drawtest.php:9) in /home/ftpserver/www/homepage/student/engjbarn/drawtest.php on line 10
‰PNG IHDRÈ–æ²/Š PLTEÈÈÈéї––ÿB „„_IDATxœí™±n„0 †)^ÚåNrÞÇ‘¸ÝHäO}Ân 4w®Úþ— ÇŸý;ˆpý…$°LW¸‘-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
thanks
cheers i got that working