forked from google/google-api-java-client-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawGraph.js
More file actions
60 lines (50 loc) · 1.78 KB
/
drawGraph.js
File metadata and controls
60 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2011 Google Inc. All Rights Reserved.
/**
* @fileoverview This script posts to the data servlet with a request for data
* to display until either the servlet responds with data or responds that it
* failed. The servlet responds to each post with a message, which the script
* displays to the user and data if it exists, which the script draws as a
* motion chart.
*
* @author lparkinson@google.com (Laura Parkinson)
*/
// Load the motion chart package from the Visualization API and JQuery.
google.load('visualization', '1', {packages: ['motionchart']});
google.load('jquery', '1.6.4');
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(doOnLoad);
function doOnLoad() {
$('#query').hide();
$('#toggle').click(function() {
$('#query').toggle();
});
$('#refresh').click(function() {
$('#refresh').attr('disabled', 'disabled');
$('#message').html('Requesting that the query be rerun...');
$.post('/', function() {
setTimeout(postCheck, 2000);
});
});
postCheck();
}
function postCheck() {
$.post('/data', function(dataObject) {
$('#message').html(dataObject.message);
if (!dataObject.data && !dataObject.failed) {
setTimeout(postCheck, 2000);
} else {
$('#refresh').removeAttr('disabled');
if (dataObject.data) {
$('#lastRun').html(dataObject.lastRun);
var width = 800;
var height = 400;
var viz = $('#visualization');
viz.css('width', width);
viz.css('height', height);
var dataTable = new google.visualization.DataTable(dataObject.data);
var motionchart = new google.visualization.MotionChart(viz[0]);
motionchart.draw(dataTable, {width: width, height: height});
}
}
}, 'json');
}