Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(!function_exists('returnGraficoData_Hora')){
- function returnGraficoData_Hora(){
- include('conexao.php');
- $sql = "SELECT TIME(data_hora) AS data_hora FROM tbdados ORDER
- BY id DESC LIMIT 4;";
- $stmt = $PDO->prepare($sql);
- $stmt->execute();
- $chartData_hora = [];
- while($linha = $stmt->fetch(PDO::FETCH_ASSOC)){
- $chartData_hora[] = "'".$linha['data_hora']."'";
- }
- echo join(",",array_reverse($chartData_hora));
- }
- }
- if(!function_exists('returnGraficoTemp')){
- function returnGraficoTemp(){
- include('conexao.php');
- $sql = "SELECT Tlm35 FROM tbdados ORDER BY id DESC LIMIT 4;";
- $stmt = $PDO->prepare($sql);
- $stmt->execute();
- $chartTemp = [];
- while($linha = $stmt->fetch(PDO::FETCH_ASSOC)){
- $chartTemp[] = "'".$linha['Tlm35']."'";
- }
- echo join(",",array_reverse($chartTemp));
- }
- }
- if(!function_exists('tabelaDados')){
- function tabelaDados(){
- include('conexao.php');
- $sql = "SELECT * FROM tbdados ORDER BY id DESC LIMIT 15;";
- $stmt = $PDO->prepare($sql);
- $stmt->execute();
- while($linha = $stmt->fetch(PDO::FETCH_OBJ)){
- $timestamp = strtotime($linha->data_hora);
- $dataTabela = date('d/m/Y H:i:s', $timestamp);
- echo "<tr>";
- echo "<td id='data'>" . $dataTabela . "</td>";
- echo "<td>" . $linha->Ax . "</td>";
- echo "<td>" . $linha->Ay . "</td>";
- echo "<td>" . $linha->Ax . "</td>";
- echo "<td>" . $linha->Gx . "</td>";
- echo "<td>" . $linha->Gy . "</td>";
- echo "<td>" . $linha->Gz . "</td>";
- echo "</tr>";
- }
- }
- }
- <div class="table-responsive">
- <table class="table table-striped table-sm">
- <thead>
- <tr>
- <th>Data/Hora</th>
- <th>Ax</th>
- <th>Ay</th>
- <th>Az</th>
- <th>Gx</th>
- <th>Gy</th>
- <th>Gz</th>
- </tr>
- </thead>
- <tbody>
- <?php
- include('../dao/leitura.php');
- tabelaDados();
- ?>
- </tbody>
- </table>
- </div>
- <script src="../js/Chart.bundle.min.js"></script>
- <script src="../js/utils.js"></script>
- <script>
- var config = {
- type: 'line',
- data: {
- labels: [<?php
- include('../dao/leitura.php');
- returnGraficoData_Hora();
- ?>],
- datasets: [{
- label: 'Temperatura',
- backgroundColor: window.chartColors.blue,
- borderColor: window.chartColors.blue,
- data: [<?php
- include('../dao/leitura.php');
- returnGraficoTemp();
- ?>],
- fill: false,
- }]
- },
- options: {
- responsive: true,
- title: {
- display: false
- },
- scales: {
- yAxes: [{
- ticks: {
- min: 0,
- max: 50
- }
- }]
- }
- }
- };
- window.onload = function() {
- var ctx = document.getElementById('grafico').getContext('2d');
- window.myLine = new Chart(ctx, config);
- };
- </script>
Add Comment
Please, Sign In to add comment