-
Notifications
You must be signed in to change notification settings - Fork 57
/
charts_change_list.html
109 lines (99 loc) · 2.62 KB
/
charts_change_list.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{% extends "admin/change_list.html" %}
{% load static %}
<!-- Override extrahead to add Chart.js -->
{% block extrahead %}
{{ block.super }}
<link rel="stylesheet" href="{% static "drf_api_logger/css/Chart.min.css" %}" />
<script src="{% static "drf_api_logger/js/Chart.bundle.min.js" %}"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const ctx = document.getElementById('countChart').getContext('2d');
const chartData = [
{% for item in analytics %}
{"date": "{{ item.added_on__date.isoformat }}", "y": {{ item.total }}},
{% endfor %}
];
// Parse the dates to JS
chartData.forEach((d) => {
d.x = new Date(d.date);
});
// Render the chart
const chart = new Chart(ctx, {
type: 'bar',
data: {
datasets: [
{
label: 'Number of API calls',
data: chartData,
backgroundColor: 'rgb(33,150,243)',
},
],
},
options: {
responsive: true,
scales: {
xAxes: [
{
type: 'time',
time: {
unit: 'day',
round: 'day',
tooltipFormat:'DD/MM/YYYY',
displayFormats: {
day: 'MMM D',
},
},
},
],
yAxes: [
{
ticks: {
beginAtZero: true,
},
},
],
},
},
});
var color = Chart.helpers.color;
var barChartData = {
labels: {{ status_code_count_keys }},
datasets: [{
label: 'Number of API calls by status code',
backgroundColor: 'rgb(33,150,243)',
borderColor: 'rgb(33,150,243)',
borderWidth: 1,
data: {{ status_code_count_values }}
}]
};
window.onload = function() {
var ctx = document.getElementById('statusCodeChart').getContext('2d');
window.myBar = new Chart(ctx, {
type: 'bar',
data: barChartData,
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'API calls by status code'
}
}
});
};
});
</script>
{% endblock %}
{% block content %}
<!-- Render our chart -->
<div style="width: 80%;">
<canvas style="margin-bottom: 30px; width: 60%; height: 50%;" id="countChart"></canvas>
</div>
<div style="width: 80%; margin-top: 24px;">
<canvas style="margin-bottom: 30px; width: 60%; height: 50%;" id="statusCodeChart"></canvas>
</div>
<!-- Render the rest of the ChangeList view -->
{{ block.super }}
{% endblock %}