Skip to content

Commit bd9c886

Browse files
8 - Chart-js Intro
1 parent 0a8a304 commit bd9c886

File tree

2 files changed

+52
-57
lines changed

2 files changed

+52
-57
lines changed

src/analytics/templates/analytics/sales.html

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,83 @@
11
{% extends "base.html" %}
22

33

4+
{% block javascript %}
5+
6+
<script>
7+
var ctx = document.getElementById("myChart").getContext('2d');
8+
var myChart = new Chart(ctx, {
9+
type: 'line',
10+
data: {
11+
labels: ["Monday", "Tues", "Wed", "Thurs", "Friday", "Sat", "Sun"],
12+
datasets: [{
13+
label: 'Sales Per Day',
14+
data: [12, 19, 3, 5, 2, 3, 49],
15+
backgroundColor: 'rgba(0, 158, 29, 0.45)',
16+
borderColor:'rgba(0, 158, 29, 1)',
17+
}]
18+
},
19+
options: {
20+
scales: {
21+
yAxes: [{
22+
ticks: {
23+
beginAtZero:true
24+
}
25+
}]
26+
},
27+
backgroundColor: 'rgba(75, 192, 192, 1)'
28+
}
29+
});
30+
</script>
31+
{% endblock %}
32+
33+
34+
435
{% block content %}
536

637

7-
<div class='row'>
38+
<div class='row my-5'>
839
<div class='col-12'>
940
<h1>Sales Data</h1>
1041
</div>
1142
</div>
1243

13-
<div class='row'>
14-
<div class='col-12'>
15-
<h1>Today's sales</h1>
16-
</div>
17-
<div class='col'>
44+
<hr/>
45+
46+
<div class='row my-5'>
47+
<div class='col-4'>
48+
<h3>Today's sales</h3>
49+
<hr/>
1850
<p>Recent Total: ${{ today.recent_data.total__sum }}</p>
1951
<ol>
20-
{% for order in today.recent %}
52+
{% for order in today.recent|slice:":5" %}
2153
<li>{{ order.order_id }}
2254
{{ order.total }}
2355
{{ order.updated }}</li>
2456
{% endfor %}
2557
</ol>
26-
</div>
27-
<div class='col'>
28-
<p>Shipped Total: ${{ today.shipped_data.total__sum }}</p>
29-
<ol>
30-
{% for order in today.shipped %}
31-
<li>{{ order.order_id }}
32-
{{ order.total }}
33-
{{ order.updated }} </li>
34-
{% endfor %}
35-
</ol>
36-
</div>
37-
<div class='col'>
38-
<p>Paid Totals: ${{ today.paid_data.total__sum }}</p>
39-
<ol>
40-
{% for order in today.paid %}
41-
<li>{{ order.order_id }}
42-
{{ order.total }}
43-
{{ order.updated }} </li>
44-
{% endfor %}
45-
</ol>
46-
</div>
47-
</div>
48-
49-
50-
51-
<div class='row'>
52-
<div class='col-12'>
53-
<h1>This week's sales</h1>
54-
</div>
55-
<div class='col'>
58+
59+
<h3>This week's sales</h3>
60+
<hr/>
5661
<p>Recent Total: ${{ this_week.recent_data.total__sum }}</p>
5762
<ol>
58-
{% for order in this_week.recent %}
63+
{% for order in this_week.recent|slice:":5" %}
5964
<li>{{ order.order_id }}
6065
{{ order.total }}
6166
{{ order.updated }}</li>
6267
{% endfor %}
6368
</ol>
6469
</div>
70+
6571
<div class='col'>
66-
<p>Shipped Total: ${{ this_week.shipped_data.total__sum }}</p>
67-
<ol>
68-
{% for order in this_week.shipped %}
69-
<li>{{ order.order_id }}
70-
{{ order.total }}
71-
{{ order.updated }} </li>
72-
{% endfor %}
73-
</ol>
74-
</div>
75-
<div class='col'>
76-
<p>Paid Totals: ${{ this_week.paid_data.total__sum }}</p>
77-
<ol>
78-
{% for order in this_week.paid %}
79-
<li>{{ order.order_id }}
80-
{{ order.total }}
81-
{{ order.updated }} </li>
82-
{% endfor %}
83-
</ol>
72+
<canvas id="myChart" width="400" height="400"></canvas>
8473
</div>
8574
</div>
8675

8776

8877

89-
<div class='row'>
78+
<hr/>
79+
80+
<div class='row my-5'>
9081
<div class='col-12'>
9182
<h1>Previous 4 weeks</h1>
9283
</div>

src/templates/base/js.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<script src='https://cdnjs.cloudflare.com/ajax/libs/jsrender/0.9.88/jsrender.min.js'></script>
1818
{% include 'base/js_templates.html' %}
1919

20+
21+
<!-- Chart.js -->
22+
<script src='https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js'></script>
23+
2024
<!-- Django Secure AJAX JS -->
2125
<script src='{% static "js/csrf.ajax.js" %}'></script>
2226

0 commit comments

Comments
 (0)