-
Notifications
You must be signed in to change notification settings - Fork 19
/
GoogleFormsVisualizer.gs
46 lines (39 loc) · 1.97 KB
/
GoogleFormsVisualizer.gs
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
/**
* This Apps Script opens up a spreadsheet, which has an attached form, by its ID.
* It creates a dashboard populated with controls and charts to enable visualization
* of the submitted form data.
* @author Kalyan Reddy (gkal.devrel@gmail.com)
*/
function doGet() {
// Open the form-attached spreadsheet by ID.
// If the URL is https://docs.google.com/spreadsheet/ccc?key=0Aq4s9w_HxMs7dGVtVGtTVWVlLV9PbnM5elktTVRFSVE#gid=0,
// the ID is 0Aq4s9w_HxMs7dGVtVGtTVWVlLV9PbnM5elktTVRFSVE
var ss = SpreadsheetApp.openById('0Aq4s9w_HxMs7dGVtVGtTVWVlLV9PbnM5elktTVRFSVE');
// Get the entire data range (all form entries).
var data = ss.getDataRange();
// Create various types of filter controls for the chart.
var ageFilter = Charts.newNumberRangeFilter().setFilterColumnIndex(2).build();
var transportFilter = Charts.newCategoryFilter().setFilterColumnIndex(3).build();
var nameFilter = Charts.newStringFilter().setFilterColumnIndex(1).build();
// Create a table chart and look at only columns 1, 2, 3, and 4.
var tableChart = Charts.newTableChart()
.setDataViewDefinition(Charts.newDataViewDefinition().setColumns([1,2,3,4]))
.build();
// Create a pie chart and look at only columns 1 and 4.
var pieChart = Charts.newPieChart()
.setDataViewDefinition(Charts.newDataViewDefinition().setColumns([1,4]))
.build();
// Create a dashboard to bind the filters to the charts.
var dashboard = Charts.newDashboardPanel().setDataTable(data)
.bind([ageFilter, transportFilter, nameFilter], [tableChart, pieChart])
.build();
// Create a UiApp to display the dashboard in.
var app = UiApp.createApplication();
var filterPanel = app.createVerticalPanel();
var chartPanel = app.createHorizontalPanel();
filterPanel.add(ageFilter).add(transportFilter).add(nameFilter).setSpacing(10);
chartPanel.add(tableChart).add(pieChart).setSpacing(10);
dashboard.add(app.createVerticalPanel().add(filterPanel).add(chartPanel));
app.add(dashboard);
return app;
}