arrowcounter/counter/templates/stats.html

53 lines
1.4 KiB
HTML
Raw Normal View History

2018-09-11 20:50:54 +00:00
{% extends 'base.html' %}
{% load static %}
{% block title %}Weekly stats{% endblock %}
{% block scripts %}
<script id="data" type="application/json">
{% autoescape off %}{{ weeklyArrows }}{% endautoescape %}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="{% static 'js/dateformat.js' %}"></script>
<script>
$(document).ready(function() {
var data = JSON.parse($('#data').text()),
format = djangoToMomentFmt(django.get_format('SHORT_DATE_FORMAT'));
console.log(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);
});
console.log(data);
var myChart = new Chart($('#chart'), {
type: 'horizontalBar',
data: {
labels: labels,
datasets: [{
label: '# of Arrows',
data: dataset,
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
});
</script>
{% endblock %}
{% block content %}
<h1 class="center">Weekly stats</h1>
<canvas id="chart"></canvas>
{% endblock %}