Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

461
Views
Chart.js MySQL PHP escala de tiempo

Me gustaría dibujar un gráfico usando RPi , MySQLi , PHP y Chart.js . Para hacer eso, seguí este tutorial :

Por ahora, mi gráfico está vacío. El eje X está 'indefinido' y el eje Y tiene un rango incorrecto. En mi caso, el eje X debería mostrar valores de formato de hora (HH:MM:SS) . ¿Alguien sabe cómo configurar correctamente los datos de tiempo recibidos de MySQL para Chart.js?

También verifiqué esta solución pero no funcionó para mí:

¡Gracias!


índice.php

 <?php $servername = "localhost"; $username = "airqualitysensor"; $password = "password"; $database = "temperatura"; $conn = new mysqli($servername, $username, $password, $database); if ($conn->connect_error){ die("Connection failed: ". $conn->connect_error); exit(); } $sql = "SELECT * FROM temperaturaodczyt"; $result = $conn->query($sql); $data = array(); foreach($result as $row){ $data[] = $row; } $result->close(); $conn->close(); print json_encode($data); ?>

aplicación.js

 $(document).ready(function(){ $.ajax({ url:"http://localhost/index.php", method: "GET", success: function(data) { console.log(data); var tczas = []; var temperatura = []; for (var i in data){ tczas.push(data[i].tczas); temperatura.push(data[i].temperatura); } var chartdata = { labels: tczas, datasets : [ { label : "Zmierzona temperatura", fill: false, lineTension: 0.1, backgroundColor: "rgb(200, 200, 200, 0.75)", borderColor: "rgb(200, 200, 200, 0.75)", hoverBackgroundColor: "rgb(200, 200, 200, 1)", hoverBorderColor: "rgb(200, 200, 200, 0.75)", data: temperatura } ] }; var ctx = $("#mycanvas"); var lineGraph = new Chart(ctx, { type: "line", data: chartdata }); }, error: function(data) { } }); });
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!