How to refresh the Gauge chart with AJAX call ?
I have tried a lot of way, but nothing is working as expected.
More details about my issue,
My Chart PHP & Data PHP pages are in /var/www/html/ directory
# ls -ltr /var/www/html/ |egrep 'chart.php|mem_use.php'
-rwxr--r-- 1 root root 131 Sep 23 16:06 mem_use.php
-rwxr--r-- 1 root root 1322 Sep 23 17:46 chart.php
My Data PHP File Content,
<?php
$old_path = getcwd();
chdir('/var/www/cgi-bin/');
$mem_use = shell_exec('./get_mem.sh');
chdir($old_path);
echo $mem_use;
?>
This will return the current memory used percentage from the system.
I have called the php manually and it giving the output perfectly, see
below :
[image: Screen Shot 2018-09-23 at 5.52.13 PM.png] <about:invalid#zClosurez>
Below are the contents of chart php file,
<html>
<head>
<script type='text/javascript'
src='https://www.google.com/jsapi'></script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
google.load('visualization', '1', {
packages: ['gauge']
});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Memory', 80],
['CPU', 55],
['Network', 68]
]);
var options = {
width: 400,
height: 120,
redFrom: 90,
redTo: 100,
yellowFrom: 75,
yellowTo: 90,
minorTicks: 5,
animation: {
duration: 700
}
};
var chart = new
google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
// dynamic update, randomly assign new values and redraw
function getData () {
$.ajax({
url: './mem_use.php',
dataType: 'text',
success: function (response) {
data.setValue(0, 1, response);
chart.draw(data, options);
setInterval(getData, 2000);
}
});
}
}
</script>
</head>
<body>
<div id='chart_div'></div>
</body>
</html>
Kindly help resolving this issue.
Regards,
Jithin C V
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/2f366150-699d-4eea-a48e-024cbc135dbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.