Jump to content


This topic is now archived and is closed to further replies.


Graph in PHP from MySQL data result ... need help in that ..

Recommended Posts

Hello friends..
Im again here from ur help .. I made a graph from MySQL data result but need a bit help to look that good and put the X:Y lines in and make as a good graph.

Here is the graph i made ...


Need help in put the X:Y lines and put the tekst on those lines like this http://svendeprove.vitusflensborg.dk/Try/bartableex1.png
Here is the code of Graph i made.

header ("Content-type: image/png");
mysql_connect('localhost', 'user', 'user');
$result = mysql_query("SELECT * FROM skemaresultat where skr_elev =".$_SESSION['userid']);

   while ($row= mysql_fetch_assoc($result))
   $values[] = $row["skr_totalpoint"];

// Get the total number of columns we are going to plot
    $columns  = count($values);

// Get the height and width of the final image
    $width = 400;
    $height = 300;

// Set the amount of space between each column
    $padding = 10;

// Get the width of 1 column
    $column_width = $width / $columns ;

// Generate the image variables
    $im        = imagecreate($width,$height);
    $gray      = imagecolorallocate ($im,0xcc,0xcc,0xcc);
    $gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
    $gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
    $white     = imagecolorallocate ($im,0xff,0xff,0xff);

// Fill in the background of the image
    $maxv = 0;

// Calculate the maximum value we are going to plot
    $maxv = max($values);

// Now plot each column
//echo $values[$i].",".$height.",".$maxv;
           $column_height = ($height / 100) * (( $values[$i] / $maxv) *100); 
           $x1 = $i*$column_width;
           $y1 = $height-$column_height;
           $x2 = (($i+1)*$column_width)-$padding;
           $y2 = $height;

// This part is just for 3D effect
// Send the PNG header information. Replace for JPEG or GIF or whatever

please help me in that ... Thanks in advance

Share this post

Link to post
Share on other sites
I have put the picture now ... can u please help me ... i really need that. pleaase help me friends.

Share this post

Link to post
Share on other sites
Check out PHPlot.php ([url=http://www.phplot.com]http://www.phplot.com[/url]), a GNU-licensed package to plot all kinds of charts, fairly easy to use, helps you concentrate on conveying your message through good-looking charts rather than spending (wasting?) time on re-inventing the wheel.

Share this post

Link to post
Share on other sites


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.