Jump to content

Small problem with producing a small 2 bar bar graph


Recommended Posts

Hello everyone, im having a really frustrating problem trying to make my graphs physically show the bars for the graph, from what i can see there are no problems with the code! but i get red x's rather than 2 bars being drawn. If anyone could shed some light onto this i would be much appreciated, i know my php version is compatible with graphics and i am using jpeg not gif images so really dont understand what could be wrong. the code:

Any help be much appreciated! :)

[code]<?php
//Produce function to call graph generation file gd.php and round percentage values to 2 decimal points to displayed beside the graphs.
//Then multiply the values for the two bars by 200 to determine the height in pixels of the bars.    

function  graphic ( $blueval , $redval ){  
$percentrd  =  round($blueval * 100,2 );  
$perccentbl  =  round($redval * 100,2 );  
$blueval  = ( $blueval * 200);  
$redval  = ( $redval * 200);  


echo  "<table><tr><td align= \"center \" >$perccentbl%</td><td>
<img src= \" gd.php?bluehg=$blueval&redhg=$redval \"  height= \" 100 \" >  
</td><td align= \" center \" >$percentrd%</td></tr></table>";  
}  

// Create  layout for graphic display and call the graphic () function  

echo  "<tr><td colspan=\"4\" align=\"center\"><table cellpadding=\"10\" border=\"1\" bgcolor=\"#B0E0E6\"><tr><td align=\"center\" valign=\"center\">";  

graphic ( $onsiteval , $offsiteval );  

echo  "</td><td align=\"center\" valign=\"center\">";
?>[/code]


The gd.php file it calls below....

[code]
<?php

Header ( "Content-Type: image/jpeg" );

// Create a 10x200 image

$im  =  ImageCreate ( 10,  200 );
// Create Colour Pallette
$red  =  ImageColorAllocate ( $im,  255,  0,  0 );
$blue  =  ImageColorAllocate ( $im ,  0 ,  0 ,  255 );
$grey  =  ImageColorAllocate ( $im , 0xC0, 0xC0 , 0xC0 );

//Fill Background of image as grey

ImageFill ( $im , 0 , 0 , $grey );

ImageFilledRectangle ($im , 0 ,0, $bluehg, 200, $blue );

ImageFilledRectangle ( $im , 6, 0, $redhg, 200, $red );

Imagejpeg($im);

?>[/code]

[b]EDIT BY OBER: PLEASE USE CODE TAGS TO POST CODE.[/b]
Hi thanks for the welcome! yep the gd libary is installed and from what my admin said i assume is enabled.

I get no errors whatsoever, just red squares for output instead of the graph like so, it is really puzzling me!
Here's what im getting lol

[img src=\"http://img.photobucket.com/albums/v96/jsxuk2000/graph.jpg\" border=\"0\" alt=\"IPB Image\" /]

yep just checked........

GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.1.9
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.