Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "pi";
  4. $password = "raspberry";
  5. $dbname = "pi";
  6.  
  7. $conn = new mysqli($servername, $username, $password, $dbname);
  8.  
  9. if ($conn->connect_error) {
  10. die("Connection failed: " . $conn->connect_error);
  11. }
  12. $sql = "SELECT * FROM data ORDER BY TempsScan DESC LIMIT 10";
  13. $result = $conn->query($sql);
  14. $temps = array();
  15. $temperatures = array();
  16. $motion = array();
  17. $distance = array();
  18. while($row = $result->fetch_assoc()) {
  19. $temps[] = $row['TempsScan'];
  20. $temperatures[] = $row['Temperatures'];
  21. $motion[] = $row['motion'];
  22. //$distance = $row['distance'];
  23. }
  24.  
  25. ?>
  26. <!doctype html>
  27. <html>
  28. <head>
  29. <title>Line Chart</title>
  30. <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.0/Chart.js"></s cript>
  31. </head>
  32. <body>
  33. <div style="width:30%">
  34. <div>
  35.  
  36. <canvas id="line-temp" width="1200" height="800"></canvas>
  37. <canvas id="line-motion" width="1200" height="800"></canvas>
  38. </div>
  39. </div>
  40. <script>
  41. new Chart(document.getElementById("line-temp"), {
  42. type: 'line',
  43. data: {
  44. labels: <?php echo json_encode(array_reverse($temps)) ?>,
  45. datasets: [{
  46. data: <?php echo json_encode(array_reverse($temperatures)) ?>,
  47. label: "Temperatures",
  48. borderColor: "#3d56ae",
  49. fill: true
  50. }
  51. ]
  52. },
  53. options: {
  54. title: {
  55. display: true,
  56. text: 'Temperatures maggle'
  57. }
  58. }
  59. });
  60.  
  61. new Chart(document.getElementById("line-motion"), {
  62. type: 'line',
  63. data: {
  64. labels: <?php echo json_encode(array_reverse($temps)) ?>,
  65. datasets: [{
  66. data: <?php echo json_encode(array_reverse($motion)) ?>,
  67. label: "Motion Detection",
  68. borderColor: "#4e934f",
  69. fill: true
  70. }
  71. ]
  72. },
  73. options: {
  74. title: {
  75. display: true,
  76. text: 'Motion maggle'
  77. }
  78. }
  79. });
  80.  
  81. new Chart(document.getElementById("line-distance"), {
  82. type: 'line',
  83. data: {
  84. labels: <?php echo json_encode($temps) ?>,
  85. datasets: [{
  86. data: <?php echo json_encode($distance) ?>,
  87. label: "Distance",
  88. borderColor: "#4e934f",
  89. fill: true
  90. }
  91. ]
  92. },
  93. options: {
  94. title: {
  95. display: true,
  96. text: ''
  97. }
  98. }
  99. });
  100.  
  101.  
  102. </script>
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement