Skip to content

Instantly share code, notes, and snippets.

/sim900a.php Secret
Created Jun 23, 2017

Embed
What would you like to do?
<?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
You can’t perform that action at this time.