Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph in stats #432

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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