-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresults.js
45 lines (37 loc) · 1.69 KB
/
results.js
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
$(function () {
Highcharts.setOptions({
credits: { enabled: false },
tooltip: { pointFormat: "{point.y}" },
legend: { enabled: false }
});
$.getJSON("data", function(data) {
$.each(data, function(i, info) {
if (info.type === "section") {
$("#contents").append("<h2 class='clear'>" + info.title + "</h2>");
} else { /* charts */
$("#contents").append("<h3 class='clear'>" + info.title + "</h3>");
var data = info.chart.series[0].data;
var height = 250;
if (info.type === "checkboxes")
height = data.length * 35;
$("<div class='graph' style='height: " + height + "px'>")
.appendTo("#contents").highcharts(info.chart);
if (info.type !== "month") {
var total = 0;
$.each(data, function(i, item) { total += item[1]; });
var table = $("<table class='response-summary-table'>")
.appendTo("#contents");
$.each(data, function(i, item) {
var tr = $("<tr>").appendTo(table);
tr.append("<td class='table-label'>" + item[0] + "</td>");
tr.append("<td class='table-number'>" + item[1] + "</td>");
tr.append("<td class='table-percentage'>" +
(item[1]/total*100).toFixed(0) + "%</td>");
});
}
}
});
}).error(function(jqXHR, status, err) {
console.log("JSON error: " + status + ': ' + err);
});
});