Guest User

Untitled

a guest
Jul 17th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. if(!function_exists('returnGraficoData_Hora')){
  2. function returnGraficoData_Hora(){
  3. include('conexao.php');
  4. $sql = "SELECT TIME(data_hora) AS data_hora FROM tbdados ORDER
  5. BY id DESC LIMIT 4;";
  6. $stmt = $PDO->prepare($sql);
  7. $stmt->execute();
  8. $chartData_hora = [];
  9.  
  10. while($linha = $stmt->fetch(PDO::FETCH_ASSOC)){
  11. $chartData_hora[] = "'".$linha['data_hora']."'";
  12. }
  13. echo join(",",array_reverse($chartData_hora));
  14. }
  15. }
  16.  
  17. if(!function_exists('returnGraficoTemp')){
  18. function returnGraficoTemp(){
  19. include('conexao.php');
  20. $sql = "SELECT Tlm35 FROM tbdados ORDER BY id DESC LIMIT 4;";
  21. $stmt = $PDO->prepare($sql);
  22. $stmt->execute();
  23. $chartTemp = [];
  24.  
  25. while($linha = $stmt->fetch(PDO::FETCH_ASSOC)){
  26. $chartTemp[] = "'".$linha['Tlm35']."'";
  27. }
  28. echo join(",",array_reverse($chartTemp));
  29. }
  30. }
  31.  
  32. if(!function_exists('tabelaDados')){
  33. function tabelaDados(){
  34. include('conexao.php');
  35. $sql = "SELECT * FROM tbdados ORDER BY id DESC LIMIT 15;";
  36. $stmt = $PDO->prepare($sql);
  37. $stmt->execute();
  38.  
  39. while($linha = $stmt->fetch(PDO::FETCH_OBJ)){
  40. $timestamp = strtotime($linha->data_hora);
  41. $dataTabela = date('d/m/Y H:i:s', $timestamp);
  42. echo "<tr>";
  43. echo "<td id='data'>" . $dataTabela . "</td>";
  44. echo "<td>" . $linha->Ax . "</td>";
  45. echo "<td>" . $linha->Ay . "</td>";
  46. echo "<td>" . $linha->Ax . "</td>";
  47. echo "<td>" . $linha->Gx . "</td>";
  48. echo "<td>" . $linha->Gy . "</td>";
  49. echo "<td>" . $linha->Gz . "</td>";
  50. echo "</tr>";
  51. }
  52. }
  53. }
  54.  
  55. <div class="table-responsive">
  56. <table class="table table-striped table-sm">
  57. <thead>
  58. <tr>
  59. <th>Data/Hora</th>
  60. <th>Ax</th>
  61. <th>Ay</th>
  62. <th>Az</th>
  63. <th>Gx</th>
  64. <th>Gy</th>
  65. <th>Gz</th>
  66. </tr>
  67. </thead>
  68. <tbody>
  69. <?php
  70. include('../dao/leitura.php');
  71. tabelaDados();
  72. ?>
  73. </tbody>
  74. </table>
  75. </div>
  76.  
  77. <script src="../js/Chart.bundle.min.js"></script>
  78. <script src="../js/utils.js"></script>
  79.  
  80. <script>
  81. var config = {
  82. type: 'line',
  83. data: {
  84. labels: [<?php
  85. include('../dao/leitura.php');
  86. returnGraficoData_Hora();
  87. ?>],
  88. datasets: [{
  89. label: 'Temperatura',
  90. backgroundColor: window.chartColors.blue,
  91. borderColor: window.chartColors.blue,
  92. data: [<?php
  93. include('../dao/leitura.php');
  94. returnGraficoTemp();
  95. ?>],
  96. fill: false,
  97. }]
  98. },
  99. options: {
  100. responsive: true,
  101. title: {
  102. display: false
  103. },
  104. scales: {
  105. yAxes: [{
  106. ticks: {
  107. min: 0,
  108. max: 50
  109. }
  110. }]
  111. }
  112. }
  113. };
  114.  
  115. window.onload = function() {
  116. var ctx = document.getElementById('grafico').getContext('2d');
  117. window.myLine = new Chart(ctx, config);
  118. };
  119. </script>
Add Comment
Please, Sign In to add comment