<?php
mysql_connect("10.237.200.202", "root", "r00tb33r") or die(mysql_error());			
mysql_select_db("spc_grinding_c1_dbo") or die(mysql_error());					
$qt=mysql_query("SELECT DataReading FROM SPC_DataReading WHERE StationNumber = 'STATION2' && MachineName = 'GN-07' && ParameterName = 'outside diameter (2.4912)' && Date_Captured = '02-25-2010' && ReadingType = 'AVERAGE'") or die(mysql_error());	
header ("Content-type: image/jpg");

$x_gap=40; // The gap between each point in y axis
$x_max=$x_gap*24; // 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=0;
$first_one="yes";

while($nt=mysql_fetch_array($qt))
{
	$x2=$x1+$x_gap; // Shifting in X axis
	$y2=$y_max-$nt[DataReading]; // Coordinate of Y axis
	ImageString($im,2,$x2,$y2,$nt[Time_Hour],$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);

?>

guys, please help me with this, the code is running if the values range from 100 - 200. but the values now are minute ones. example 2.49912 and so on..how is it possible?

guys, please help me with this, the code is running if the values range from 100 - 200. but the values now are minute ones. example 2.49912 and so on..how is it possible?

Hello,

I didn't find anything significantly wrong with the code. Some comments:

1) what would be your expectation for small values like 2.499? Is the value in itself wrong or does the code above not produce an image when small values show up?

2) imageline expects integer values for all x,y coordinates. So rounding before feeding it into the imageline command might help.

3) Can negative numbers occur? The code makes no provision for this. In general there are no checks for erroneous input in the graph portion. What about values that exceed 250? Some form of clipping might help. Like

if ($x2 < 0) $x2 = 0;

or for the other extreme

if ($x2 >249) $x2 = 249;

Please note the 249. If you define an image with dimensions 300 wide, 250 high for example, your min value is 0 and your respective max values are 249 and 299.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.