Jump to content

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


sibga

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

[img]http://svendeprove.vitusflensborg.dk/try/untitled.bmp[/img]

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.

<?php
header ("Content-type: image/png");
ob_start();
session_start();
         
mysql_connect('localhost', 'user', 'user');
mysql_select_db('pilot');
$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
    imagefilledrectangle($im,0,0,$width,$height,$white);
    $maxv = 0;

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

// Now plot each column
      for($i=0;$i<$columns;$i++)
       {
//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;
imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);

// This part is just for 3D effect
imageline($im,$x1,$y1,$x1,$y2,$gray_lite);
imageline($im,$x1,$y2,$x2,$y2,$gray_lite);
imageline($im,$x2,$y1,$x2,$y2,$gray_dark);
}
// Send the PNG header information. Replace for JPEG or GIF or whatever
     imagepng($im);
?>       

please help me in that ... Thanks in advance
Link to comment
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.
Link to comment
Share on other sites

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.