-
-
Save anonymous/eb9ca25eed7f6eb5779428e4290be77e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include('phpgraphlib.php'); | |
$conn = mysql_connect ('localhost','root'); //or die ('could not connect' .mysql_error()); | |
if (!$conn) | |
{ | |
die ('Could not connect' .mysql_error()); | |
} | |
mysql_select_db("temperature",$conn) or die ('Could not select database:'.mysql_error()); | |
//$dataArray = array(); | |
$temparray = array(); | |
$humarray = array(); | |
//getting data from the database | |
$sql= "SELECT * FROM th ORDER BY Time DESC LIMIT 10"; | |
$result = mysql_query($sql) or die ('data could not be selected'.mysql_error()); | |
//if($query_run=$sql) | |
if($result) | |
{ | |
while ($row = mysql_fetch_assoc($result)) | |
{ | |
$time = $row["time"]; | |
$count = $row["temp"]; | |
$temparray[$time]= $count; | |
$count = $row["hum"]; | |
$humarray[$time] = $count; | |
} | |
} | |
//creating the phpgraphlibObject | |
$graph=new phpgraphlib(300, 200); | |
//adding data to the graph. Calling the addData() function | |
$graph->addData("$temparray, $humarray"); | |
//customising the graph | |
$graph->setTitle("Temperature and Humidity Graph"); | |
$graph->setTitleLocation("left"); | |
$graph->setupYAxis(12, 'blue'); | |
$graph->setupXAxis(20); | |
$graph->setBarColor('green','blue'); | |
$graph->setDataValues(true); | |
$graph->setDataValuesColor('red'); | |
$graph->setLegend(true); | |
$graph->setLegendOutlineColor('white'); | |
$graph->setLegendTitle('Temperature', 'Humidity'); | |
$graph->setXValuesHorizontal(false); | |
$graph->setColor("red"); | |
$graph->setGradient("lime","blue"); | |
$graph->setOutlineColor("black"); | |
//finalizing the graph | |
$graph->CreateGraph(); | |
mysql_close($conn); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment