2019-04-28 11:44:52 +00:00
|
|
|
'use strict';
|
|
|
|
// vim: set ts=2 sw=2 tw=80 et:
|
2018-09-11 20:58:07 +00:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
var data = JSON.parse($('#data').text()),
|
|
|
|
format = djangoToMomentFmt(django.get_format('SHORT_DATE_FORMAT'));
|
2019-04-28 11:44:52 +00:00
|
|
|
var chart = $('#chart');
|
2018-09-11 20:58:07 +00:00
|
|
|
var labels = [], dataset = [];
|
2019-04-28 11:44:52 +00:00
|
|
|
|
|
|
|
// Set the chart height in em according to length of dataset
|
|
|
|
chart.css("height", "" + (2 * data.length) + "rem");
|
|
|
|
// Force height in pixels in order to fix infinite growth resizing bug of
|
|
|
|
// chart.js
|
|
|
|
chart.attr("height", chart.height());
|
|
|
|
|
2018-09-11 20:58:07 +00:00
|
|
|
data.forEach(function(d) {
|
|
|
|
labels.push(moment(d.weekStarts).format(format) + ' - ' +
|
|
|
|
moment(d.weekEnds).format(format));
|
|
|
|
dataset.push(d.sum_count);
|
|
|
|
});
|
2019-04-28 11:44:52 +00:00
|
|
|
|
|
|
|
var chart = new Chart(chart, {
|
|
|
|
type: 'horizontalBar',
|
|
|
|
data: {
|
|
|
|
labels: labels,
|
|
|
|
datasets: [{
|
|
|
|
label: '# of Arrows',
|
|
|
|
data: dataset,
|
|
|
|
borderWidth: 1
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
scales: {
|
|
|
|
xAxes: [{
|
|
|
|
ticks: {
|
|
|
|
beginAtZero: true
|
2018-09-11 20:58:07 +00:00
|
|
|
}
|
2019-04-28 11:44:52 +00:00
|
|
|
}]
|
2018-09-11 20:58:07 +00:00
|
|
|
}
|
2019-04-28 11:44:52 +00:00
|
|
|
}
|
2018-09-11 20:58:07 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|