hi guys,
i had some error code below which is used to plot data from SQL query result into a graph:
require_once('as-diagrams.php');
require_once ('lib/jpgraph/jpgraph.php');
require_once ('lib/jpgraph/jpgraph_line.php');
require_once( "lib/jpgraph/jpgraph_date.php");
$datax = array();
$datay = array();
//let's say this is the range date as input
$date1 = "2011-05-01";
$date2 = "2011-05-08";
$con = mssql_connect("EV0021919ECCC0","username", "password") or die("unnable to connect");
mssql_select_db("database");
set_time_limit (1000);
$rs = mssql_query("SELECT distinct day, maxload
FROM dbo.BO_BUSYHOUR_CPLOAD2
WHERE (ne = 'MSJK5') AND ([day]>='$date1' AND [day]<='$date2' ) ORDER BY [day] ");
//day should return 2011-05-01, 2011-05-02, ..., 2011-05-08 as result
//maxload should return values 56.01, 53.52, 54.54, 53.16, etc. (appear in eight times, following the dates)
while($result = mssql_fetch_array($rs))
{
$datay[] = $result['maxload'];
$datax[] = strtotime($result['day']);
}
// Size of the overall graph
$width=650;
$height=500;
// Create the graph and set a scale.
// These two calls are always required
$graph = new Graph($width,$height);
$graph->SetScale('datlin');
$graph->xaxis->SetLabelAngle(90);
$graph->SetShadow();
// Setup margin and titles
$graph->SetMargin(40,40,30,100);
$graph->SetAlphaBlending();
$graph->title->Set('Jakarta Inner Busy Hour CP Load (%)');
$graph->yaxis->title->Set('CP Load (%)');
$graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD );
$graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD );
$graph->yaxis->SetColor('cyan');
// Use hour:minute format for the labels
$graph->xaxis->scale->SetDateFormat('Y-m-d');
/*$a = $gDateLocale->GetShortMonth();
$graph->xaxis->SetTickLabels($a);*/
// Create the linear plot
$lineplot = new LinePlot($datay,$datax);
$lineplot->SetColor( 'blue' );
$lineplot->SetWeight( 2 ); // Two pixel wide
$lineplot->mark->SetType(MARK_UTRIANGLE);
$lineplot->mark->SetColor('blue');
$lineplot->mark->SetFillColor('red');
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();
the result shows in the attached file below, or u can just view from this link:
http://www.phpbuilder.com/board/attachment.php?attachmentid=4298&stc=1&d=1305792120
as u can see..
the dates are getting doubled on each day..
is there any mistakes in my code so that the result threw that way??
or should i have to add more line of codes to prevent this output??
thx before