Hello! I am quite new to MagicMirror and trying to display personal data from a MySQL database (stored on amazon cloud) in text and graphs on my mirror. I currently have a mixture of html and php files to access the data and display on a website. I would like to transfer the functionality but am unsure how to do so in a compatible way.
I currently doing so with php:
$db = mysqli_connect(REDACTED) or die('Error connecting to MySQL server.');
//the SQL query to be executed
$query = "SELECT * FROM table";
//storing the result of the executed query
$result = $db->query($query);
//initialize the array to store the processed data
$jsonArray = array();
//check if there is any data returned by the SQL Query
if ($result->num_rows > 0) {
//Converting the results into an associative array
while($row = $result->fetch_assoc()) {
$date= $row['timestamp'];
$jsonArrayItem = array();
$jsonArrayItem['label'] = $date;
$jsonArrayItem['value'] = $row['columnName'];
//append the above created object into the main array.
array_push($jsonArray, $jsonArrayItem);
}
}
//Closing the connection to DB
$db->close();
//set the response content type as JSON
header('Content-type: application/json');
//output the return value of json encode using the echo function.
echo json_encode($jsonArray);
?>
And then displaying with Fusion charts:
$(function(){
$.ajax({
url: 'http://REDACTED',
type: 'GET',
success : function(data) {
chart1Data = data;
var chart4Properties = {
"caption": " ",
"xAxisName": "Date",
"yAxisName": " ",
"rotatevalues": "1",
"theme": "zune"
};
api4Chart = new FusionCharts({
type: 'column2d',
renderAt: 'chart4-container',
width: '550',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": chart4Properties,
"data": chart1Data
}
});
api4Chart.render();
}
});
});
Any help would be appreciated. If there is any other information I can provide, please let me know. Thank you :)