Moved weekly stats js in separate script and chart x axis starts from 0

This commit is contained in:
Claudio Maggioni 2018-09-11 22:58:07 +02:00
parent debb3bbee9
commit 718d6b7bba
2 changed files with 36 additions and 34 deletions

View file

@ -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
}
}]
}
}
});
});

View file

@ -10,40 +10,7 @@
<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>
<script src="{% static 'js/weeklystats.js' %}"></script>
{% endblock %}
{% block content %}