Hi,
I looked at “How can I use PHP MySQL Dynamic data” Forum and attempted to get my graph to work but am having trouble even displaying a dynamic graph with data. Eventually I want to be able to sum my count value and have the dynamic graph tick every second with the new query sum(count) value. Before I get there, I was hoping to just get a dynamic graph to work with my MySQL table. Here is my PHP code:
<?php
header(‘Content-Type: application/json’);
$con = mysqli_connect(“18.85.28.15″,”lindsay”,”McGelin123!”,”python”);
// Check connection
if (mysqli_connect_errno($con))
{
echo “Failed to connect to DataBase: ” . mysqli_connect_error();
}else
{
$data_points = array();
$result = mysqli_query($con, “SELECT count, timestamp FROM skelCount”);
while($row = mysqli_fetch_array($result))
{
$point = array(“label” => $row[‘timestamp’] , “y” => $row[‘count’]);
array_push($data_points, $point);
}
echo json_encode($data_points, JSON_NUMERIC_CHECK);
}
mysqli_close($con);
?>
And here is my HTML code:
<!DOCTYPE html>
<head>
<!– javascript –>
<script type=”text/javascript” src=”js/jquery.canvasjs.min.js”></script>
<script type=”text/javascript” src=”js/canvasjs.min.js”></script>
<script type=”text/javascript”>
$(document).ready(function () {
$.getJSON(“canvas-json-return.php”, function (result) {
var chart = new CanvasJS.Chart(“chartContainer”, {
data: [
{
dataPoints: result
}
]
});
chart.render();
});
});
</script>
</head>
<body>
<div id=”chartContainer” style=”width: 800px; height: 380px;”></div>
</body>
</html>