Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 sibga

sibga
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 August 2006 - 04:27 AM

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

http://svendeprove.v...ry/untitled.bmp

Need help in put the X:Y lines and put the tekst on those lines like this http://svendeprove.v...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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 August 2006 - 06:27 AM

Link to your graph does not display  - errors in code
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 sibga

sibga
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 August 2006 - 06:54 AM

I have put the picture now ... can u please help me ... i really need that. pleaase help me friends.

#4 sibga

sibga
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 15 August 2006 - 07:06 AM

please help me i really need that pleaseee

#5 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 15 August 2006 - 07:41 AM

You really need to learn proper spelling and punctuation.

#6 Cook

Cook
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationSingapore

Posted 15 August 2006 - 08:25 AM

Check out PHPlot.php (http://www.phplot.com), 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.
Cook




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users