I am doing a project where I have to update a Temperature Gauge and a Chart with data from a database (MySQL). I have created a webpage, created the database table, used a gauge from Google Charts but I do not how to get the gauge to work using the data from the database.
Here is the code for the gauge, I need to know what type of code that I have to use (AJAX, JSON etc) and then how do I get the result in to the gauge.
<script type="text/javascript">
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Temp°C', 19], <!--Change temperature here-->
]);
<!--size of the gauge and some detail that can be altered here-->
var options = {
width: 400, height: 120,
blueFrom: 0, blueTo: -10,
greenFrom: 0, greenTo:20,
redFrom: 40, redTo: 100,
yellowFrom:20, yellowTo: 40,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
setInterval(function() {
data.setValue(0, 1, 40 + Math.round(jsonData));
chart.draw(data, options);
}, 500);
}
</script>
I have been going crazy for the past week so any help or guidance will be much appreciated.