In order to use jQuery's AJAX function, you need to include jQuery:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
></script>
The try this:
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Flow', 0]
]);
var options = {
width: 400,
height: 120,
redFrom: 90,
redTo: 100,
yellowFrom: 75,
yellowTo: 90,
minorTicks: 5
};
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: 'Gauge.php',
success: function (response) {
data.setValue(0, 1, response);
chart.draw(data, options);
setTimeout(getData, 5000);
}
});
}
getData();
}
google.load('visualization', '1', {packages: ['gauge'], callback:
drawChart});
On Thursday, August 29, 2013 3:36:06 AM UTC-4, Nallacheruvu STP wrote:
>
> Where to incorporate that function in following code and please correct
> the code if necessary.
>
>
> <html>
> <head>
> <script type='text/javascript' src='
> https://www.google.com/jsapi'></script>
> <script type="text/javascript">
> google.load('visualization', '1', {
> packages: ['gauge']
> });
> google.setOnLoadCallback(drawChart);
>
>
>
> function drawChart() {
> var data = google.visualization.arrayToDataTable([
> ['Label', 'Value'],
> *['Flow', 0]*
> ]);
>
> var options = {
> width: 400,
> height: 120,
> redFrom: 90,
> redTo: 100,
> yellowFrom: 75,
> yellowTo: 90,
> minorTicks: 5
> };
> var chart = new
> google.visualization.Gauge(document.getElementById('chart_div'));
> chart.draw(data, options);
>
> // dynamic update, randomly assign new values and redraw
>
>
> *setInterval(function() {*
> * var flow = $.ajax({url: 'Gauge.php', dataType: 'text', async:
> false}).responseText;*
> * data.setValue(0, 1, flow);*
> * chart.draw(data, options);*
> * }, 5000);*
> *
> *
> *
> *
> </script>
> </head>
> <body>
> <div id='chart_div'></div>
> </body>
> </html>
>
--
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 http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.