aboutsummaryrefslogtreecommitdiff
path: root/admin/public/votes.js
diff options
context:
space:
mode:
authorMarvin Borner2020-10-10 17:49:51 +0200
committerMarvin Borner2020-10-10 17:49:51 +0200
commit897b4173c5cc190805a96aafe5f9258610332e39 (patch)
treeffd3e52712e2a8decfa2ec882c0110b0c10e61fd /admin/public/votes.js
parentb2d9cf884f2aff3445d6619939186e48a683e5a9 (diff)
Added vote stats
Diffstat (limited to 'admin/public/votes.js')
-rw-r--r--admin/public/votes.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/admin/public/votes.js b/admin/public/votes.js
new file mode 100644
index 0000000..3f1284c
--- /dev/null
+++ b/admin/public/votes.js
@@ -0,0 +1,37 @@
+fetch("api/votes")
+ .then((response) => response.json())
+ .then((response) => {
+ const ctx = document.getElementById("votes").getContext("2d");
+ new Chart(ctx, {
+ type: "bar",
+ data: {
+ labels: response.map((v) => v.name),
+ datasets: [
+ {
+ label: "# of Votes",
+ data: response.map((v) => v.votes || 0),
+ backgroundColor: () => "#" + (Math.random().toString(16) + "0000000").slice(2, 8),
+ borderWidth: 1,
+ },
+ ],
+ },
+ options: {
+ legend: {
+ display: false,
+ },
+ tooltips: {
+ enabled: false,
+ },
+ scales: {
+ yAxes: [
+ {
+ ticks: {
+ beginAtZero: true,
+ precision: 0,
+ },
+ },
+ ],
+ },
+ },
+ });
+ });