-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
83 lines (71 loc) · 1.77 KB
/
index.html
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!doctype html>
<html>
<head>
<title>Bar Chart</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.13.1/js-yaml.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" type="css/stylesheet">
<style>
#container {
margin: auto;
}
canvas {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<div id="container" style="width: 75%;">
<canvas id="bar-chart"></canvas>
</div>
<script>
function generateColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
var client = new XMLHttpRequest();
client.open('GET', 'data/groups.yml');
client.onreadystatechange = function() {
const doc = jsyaml.load(client.responseText);
console.log(doc);
var labels = []
var counts = []
var colors = []
// Make a list of labels and counts
$.each(doc, function(e, entry){
labels.push(entry[0])
counts.push(entry[1])
colors.push(generateColor())
})
new Chart(document.getElementById("bar-chart"), {
type: 'bar',
data: {
labels: labels,
datasets: [
{
label: "Counts (posts and replies)",
backgroundColor: colors,
data: counts
}
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Ask Cyberinfrastructure Contributions by Group'
}
}
});
}
client.send();
</script>
</body>
</html>