Skip to content

Commit

Permalink
graph in stats (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
sid22 authored and Martti Sasi committed Jul 24, 2017
1 parent 6257742 commit e43e7fa
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
76 changes: 76 additions & 0 deletions website/templates/stats.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends "base.html" %}
{% load staticfiles %}

{% block content %}
<script type="text/javascript" src="{% static 'js/Chart.bundle.min.js' %}"></script>
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Stats</h1>
Expand Down Expand Up @@ -78,4 +80,78 @@ <h3>{{extension_users}} Extension users</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<canvas id="myChart" width="100" height="100"></canvas>
<br>
</div>
</div>
<script type="text/javascript">
var all_months = ["Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
var months = [], data = [];
var all_data = new Array(12).fill(0);

{% for i in graph %}
all_data[{{i.month}}] = {{i.c}};
{% endfor %}
console.log(all_data);
months = all_months;
data = all_data;
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: months,
datasets: [{
label: 'Monthly Activity',
data: data,
backgroundColor: [
'rgba(255, 99, 132, 0.6)',
'rgba(54, 162, 235, 0.6)',
'rgba(255, 206, 86, 0.6)',
'rgba(75, 192, 192, 0.6)',
'rgba(153, 102, 255, 0.6)',
'rgba(255, 159, 64, 0.6)',
'rgba(255, 99, 132, 0.6)',
'rgba(54, 162, 235, 0.6)',
'rgba(255, 206, 86, 0.6)',
'rgba(75, 192, 192, 0.6)',
'rgba(153, 102, 255, 0.6)',
'rgba(255, 159, 64, 0.6)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)',
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
fixedStepSize: 1
}
}],
xAxes: [{
time: {
unit: 'month'
}
}]
}
}
});
</script>

{% endblock %}
1 change: 1 addition & 0 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def get_context_data(self, *args, **kwargs):
context['user_count'] = User.objects.all().count()
context['hunt_count'] = Hunt.objects.all().count()
context['domain_count'] = Domain.objects.all().count()
context['graph']= Issue.objects.annotate(month=ExtractMonth('created')).annotate(c=Count('id')).order_by()
return context


Expand Down

0 comments on commit e43e7fa

Please sign in to comment.