Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // connect to the database
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "plottest";
- $dbLink = mysqli_connect($servername, $username, $password, $dbname);
- if (!$dbLink) {
- die("Connection failed: " . mysqli_connect_error());
- }
- /*
- * read the data from the result set and output
- * to the graphing software
- */
- $sql = "SELECT * FROM plottest01 ORDER BY time";
- $result = mysqli_query($dbLink, $sql);
- $dataNum = 1;
- $dataPoints = array();
- while ( $row = mysqli_fetch_assoc($result) )
- {
- array_push($dataPoints, array("x" => $row["data"], "y" => $row["data"]));
- }
- // close the databse connection
- mysqli_close($dbLink);
- ?>
- <!DOCTYPE HTML>
- <html>
- <head>
- <script type="text/javascript">
- window.onload = function () {
- var chart = new CanvasJS.Chart("chartContainer", {
- title: {
- text: "Push-ups Over a Week"
- },
- axisX: {
- valueFormatString: "YYYY-MM-DD HH:mm:ss"
- },
- axisY: {
- title: "Number of Push-ups"
- },
- data: [{
- type: "line",
- dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
- }]
- });
- chart.render();
- }
- </script>
- </head>
- <body>
- <div id="chartContainer" style="height: 370px; width: 100%;"></div>
- <script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement