Fakultas Ilmu Komputer UI

statistik.html 2.02 KB
Newer Older
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
{% extends 'app/base_dashboard.html' %}
{% load static %}

{% block title %}
<title>Unggah Materi dari Excel | Digipus</title>
{% endblock %}

{% block stylesheets %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"
    integrity="sha512-d9xgZrVZpmmQlfonhQUvTR7lMPtO7NkZMkA0ABN3PHCbKA5nqylQ/yWlFAyY6hYgdF1Qh6nYiuADWwKB4C2WSw=="
    crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.css"
    integrity="sha512-/zs32ZEJh+/EO2N1b0PEdoA10JkdC3zJ8L5FTiQu82LR9S/rOQNfQN7U59U9BC12swNeRAz3HSzIL2vpp4fv3w=="
    crossorigin="anonymous" />
{% endblock %}

{% block content %}


<div class="container">

    <h1 class="h3 mb-2 text-gray-800">Summary Materi per Kategori</h1>

    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered">
27
                <caption>Summary Materi per Kategori</caption>
28
                <thead>
29
30
                    <th scope="col">Kategori</th>
                    <th scope="col">Jumlah Materi</th>
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
                </thead>
                <tbody>
                    {% for s in stats %}
                    <tr>
                        <td>{{s.name}}</td>
                        <td>{{s.num}}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div class="col-lg-6 mx-auto">
        <canvas id="myChart" width="400" height="400"></canvas>
    </div>

</div>

<script type="text/javascript">

    function displayChart(data) {
        var ctx = document.getElementById('myChart').getContext('2d');

        var myChart = new Chart(ctx, {
            type: 'pie',
            data: data
        });
    }


    document.addEventListener("DOMContentLoaded", function(){
        fetch('/stats?data=json')
        .then(function(response) { 
            return response.json()
        })
        .then(function(json) {
            displayChart(json)
       })
    });

</script>
{% endblock %}