Advertisement
Guest User

Untitled

a guest
May 3rd, 2012
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <?php
  2.  
  3. /* pChart library inclusions */
  4. include("pchart/class/pData.class.php");
  5. include("pchart/class/pDraw.class.php");
  6. include("pchart/class/pImage.class.php");
  7.  
  8. $con = mysql_connect("","","");
  9. if (!$con)
  10. {
  11. die('Could not connect: ' . mysql_error());
  12. }
  13.  
  14. mysql_select_db("weather",$con);
  15.  
  16. $result = mysql_query("SELECT hour(time) as time, temp_out FROM wmr200 WHERE date(time) = curdate()");
  17.  
  18. $time = array();
  19. $temp = array();
  20.  
  21. while($row = mysql_fetch_array($result))
  22. {
  23. $time[] = $row['time'];
  24. $temp[] = $row['temp_out'];
  25. }
  26.  
  27. $prev = -1;
  28. foreach ($time as &$hour) {
  29. if ($prev === $hour) {
  30. $hour = NULL;
  31. }
  32. else {
  33. $prev = $hour;
  34. }
  35. }
  36.  
  37. mysql_close($con);
  38.  
  39. /* Create and populate the pData object */
  40. $MyData = new pData();
  41. $MyData->addPoints($temp,"Temperature");
  42. $MyData->addPoints($time,"Time");
  43. $MyData->setAxisName(0,"Temperature °C");
  44. $MyData->setSerieTicks("Time",1000);
  45. $MyData->setAbscissa("Time");
  46. #$MyData->setXAxisDisplay(AXIS_FORMAT_TIME,"H");
  47.  
  48.  
  49. /* Create the pChart object */
  50. $myPicture = new pImage(600,400,$MyData);
  51.  
  52. /* Draw the background */
  53. #$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
  54. #$myPicture->drawFilledRectangle(0,0,700,230,$Settings);
  55.  
  56. /* Draw the scale and the 1st chart */
  57. $myPicture->setGraphArea(50,20,550,130);
  58. $myPicture->drawScale(array("DrawSubTicks"=>FALSE,"DisplayValues"=>FALSE,"LabelRotation"=>0));
  59. $myPicture->drawLineChart(array("DisplayValues"=>FALSE,"DisplayColor"=>DISPLAY_AUTO));
  60. $myPicture->setShadow(FALSE);
  61. $myPicture->Antialias = FALSE;
  62.  
  63.  
  64. /* Render the picture (choose the best way) */
  65. $myPicture->autoOutput("pictures/example.drawLineChart.png");
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement