Hello to everyone,
Im trying to create a line graph / chart
Im using a code i found on google
<?php
include 'config.php';
$do_date = $_GET['day'];
$do_month = $_GET['month'];
$do_year = $_GET['year'];
$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
$qt=mysql_query("SELECT * FROM users WHERE do_date = \"$do_date\" AND do_month = \"$do_month\" AND do_year = \"$do_year\" AND username = \"davidspalton\"");
header ("Content-type: image/jpg");
$x_gap=70; // The gap between each point in y axis
$x_max=$x_gap*7; // Maximum width of the graph or horizontal axis
$y_max=250; // Maximum hight of the graph or vertical axis
// Above two variables will be used to create a canvas of the image//
$im = @ImageCreate ($x_max, $y_max)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 234, 234, 234);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
$graph_color = ImageColorAllocate ($im,25,25,25);
$x1=0;
$y1=250;
$first_one="yes";
while($nt=mysql_fetch_array($qt)){
//echo "$nt[b_reading], $nt[r_period]";
$x2=$x1+$x_gap; // Shifting in X axis
$y2=$y_max-$nt[b_reading]; // Coordinate of Y axis
ImageString($im,2,$x2,$y2,$nt[r_period],$graph_color);
//Line above is to print month names on the graph
if($first_one=="no"){ // this is to prevent from starting $x1= and $y1=0
imageline ($im,$x1, $y1,$x2,$y2,$text_color); // Drawing the line between two points
}
$x1=$x2; // Storing the value for next draw
$y1=$y2;
$first_one="no"; // Now flag is set to allow the drawing
}
ImageJPEG ($im);
?>
It pulls the results from the db based on the day, month and year
My problem is I want to add the x & y axis with titles, but mostly its all bunched down at the bottom, with a big gap at the top.
Ideally id like the height to show as no more than 30 and the width to be the number of results.
Then (not asking much), is it possible to put a 'point' where the result is on the line?
thank in advance for all the help
David