-
Notifications
You must be signed in to change notification settings - Fork 13
/
analytics_file_types.html
68 lines (57 loc) · 2.43 KB
/
analytics_file_types.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
---
title: File types
layout: default
permalink: /analytics/file-types/
---
{% include breadcrumbs.html parent="Analytics" %}
<h2>{{page.title}}</h2>
<canvas id="chart-file-types" width="400" height="200"></canvas>
<canvas id="chart-file-types-by-org" width="400" height="200"></canvas>
<canvas id="chart-file-types-per-dataset" width="400" height="200"></canvas>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Loading the datasets data
$.getJSON('/datasets.json', function (datasets) {
// Load charts
chartFileTypes(datasets);
});
});
function chartFileTypes(datasets) {
let ctx = document.getElementById('chart-file-types').getContext('2d');
let data = _.chain(datasets)
.map(dataset => dataset.resources.map(resource => resource.format))
.flatten()
.groupBy()
.map((value, key) => ({ label: key, count: value.length }))
.orderBy('count', 'desc')
.value();
let labels = _.chain(data)
.map('label')
.value();
let values = _.chain(data)
.map('count')
.value();
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: '# of file types in datasets',
data: values,
backgroundColor: 'rgba(31, 120, 180, 1)',
borderColor: 'rgba(31, 120, 180, 0.5)',
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
</script>