From 718d6b7bba56820bcb4e7a047301c07f30c59110 Mon Sep 17 00:00:00 2001 From: praticamentetilde Date: Tue, 11 Sep 2018 22:58:07 +0200 Subject: [PATCH] Moved weekly stats js in separate script and chart x axis starts from 0 --- counter/static/js/weeklystats.js | 35 ++++++++++++++++++++++++++++++++ counter/templates/stats.html | 35 +------------------------------- 2 files changed, 36 insertions(+), 34 deletions(-) create mode 100644 counter/static/js/weeklystats.js diff --git a/counter/static/js/weeklystats.js b/counter/static/js/weeklystats.js new file mode 100644 index 0000000..46686b7 --- /dev/null +++ b/counter/static/js/weeklystats.js @@ -0,0 +1,35 @@ +'use strict'; + +$(document).ready(function() { + var data = JSON.parse($('#data').text()), + format = djangoToMomentFmt(django.get_format('SHORT_DATE_FORMAT')); + var labels = [], dataset = []; + + data.forEach(function(d) { + labels.push(moment(d.weekStarts).format(format) + ' - ' + + moment(d.weekEnds).format(format)); + dataset.push(d.sum_count); + }); + + var chart = new Chart($('#chart'), { + type: 'horizontalBar', + data: { + labels: labels, + datasets: [{ + label: '# of Arrows', + data: dataset, + borderWidth: 1 + }] + }, + options: { + scales: { + xAxes: [{ + ticks: { + beginAtZero: true + } + }] + } + } + }); +}); + diff --git a/counter/templates/stats.html b/counter/templates/stats.html index 0246741..e1d4218 100644 --- a/counter/templates/stats.html +++ b/counter/templates/stats.html @@ -10,40 +10,7 @@ - + {% endblock %} {% block content %}