So I was able to export to json format, but not sure if the format is right for the chart.
but the chart is not showing… can someone help with this one
<html>
<head>
<title>Highcharts Live Test</title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/highcharts.js"></script>
<script>
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
function requestData() {
$.ajax({
// url: 'live-server-data.php',
url: 'https://mpimold.com/123/jsonexport.php',
success: function (point) {
var series = chart.series[0],
shift = series.data.length > 20;
console.log(point);
var timestamp = point[0];
var date = new Date(timestamp);
console.log(date);
chart.series[0].addPoint(point, true, shift);
setTimeout(requestData, 1000);
},
cache: false
});
}
$(function () {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Value',
margin: 80
}
},
series: [{
name: 'Random data',
data: []
}]
});
});
</script>
<div id="container" style="width: 100%; height: 400px">
</div>
</body>
</html>
php
<?php
//open connection to mysql db
$connection = mysqli_connect("localhost","user","pass","dbname") or die("Error " . mysqli_error($connection));
//fetch table rows from mysql db
$sql = "select id, sensor1 from SensorData";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
//create an array
while($row =mysqli_fetch_assoc($result))
{
$emparray[]= array($row['id'], $row['sensor1']);
}
echo json_encode($emparray);
//write to json file
$fp = fopen('json.json', 'w');
fwrite($fp, json_encode($emparray));
fclose($fp);
//close the db connection
mysqli_close($connection);
?>