Advertisement
Guest User

Untitled

a guest
May 11th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <?php
  2. // connect to the database
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "plottest";
  7. $dbLink = mysqli_connect($servername, $username, $password, $dbname);
  8. if (!$dbLink) {
  9. die("Connection failed: " . mysqli_connect_error());
  10. }
  11. /*
  12. * read the data from the result set and output
  13. * to the graphing software
  14. */
  15. $sql = "SELECT * FROM plottest01 ORDER BY time";
  16. $result = mysqli_query($dbLink, $sql);
  17.  
  18. $dataNum = 1;
  19. $dataPoints = array();
  20. while ( $row = mysqli_fetch_assoc($result) )
  21. {
  22. array_push($dataPoints, array("x" => $row["data"], "y" => $row["data"]));
  23. }
  24.  
  25. // close the databse connection
  26. mysqli_close($dbLink);
  27. ?>
  28.  
  29. <!DOCTYPE HTML>
  30. <html>
  31. <head>
  32. <script type="text/javascript">
  33.  
  34. window.onload = function () {
  35.  
  36. var chart = new CanvasJS.Chart("chartContainer", {
  37. title: {
  38. text: "Push-ups Over a Week"
  39. },
  40. axisX: {
  41. valueFormatString: "YYYY-MM-DD HH:mm:ss"
  42. },
  43. axisY: {
  44. title: "Number of Push-ups"
  45. },
  46. data: [{
  47. type: "line",
  48. dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
  49. }]
  50. });
  51. chart.render();
  52.  
  53. }
  54.  
  55. </script>
  56. </head>
  57. <body>
  58. <div id="chartContainer" style="height: 370px; width: 100%;"></div>
  59. <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement