-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafik-dataLB.php
147 lines (133 loc) · 4.31 KB
/
grafik-dataLB.php
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<div class="modal fade" id="grafikLB" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog mw-100 w-75" role="document">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title text-center w-100 fw-bold fs-4">Grafik Luka Berat</div>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<canvas id="grafikHasilLB" width="200" height="100"></canvas>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
<?php
if (isset($_SESSION['grafik_hasil_LB'])) {
$data_hasilLB = $_SESSION['grafik_hasil_LB'];
$data_realLB = $_SESSION['grafik_hasil_datarealLB'];
$tahun_data_realLB = $_SESSION['grafik_tahun_data_realLB'];
$tahun_data_hasilLB = $_SESSION['grafik_tahun_hasilLB'];
$nilaiMax_LB = max($data_hasilLB) >= max($data_realLB) ?(int) max($data_hasilLB) : (int) max($data_realLB);
$max_sumbuY_LB = $nilaiMax_LB % 2 == 0 ? $nilaiMax_LB + 4 : $nilaiMax_LB + 3;
}
?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-annotation/0.5.7/chartjs-plugin-annotation.min.js"></script>
<?php if (isset($_SESSION['grafik_hasil_LB'])) : ?>
<script>
let yHasilLB = <?= json_encode($data_hasilLB); ?>;
let yRealLB = <?= json_encode($data_realLB); ?>;
let max_sumbuyLB = <?= json_encode($max_sumbuY_LB); ?>;
let tahun_hasilLB = <?= json_encode($tahun_data_hasilLB); ?>;
let tahun_realLB = <?= json_encode($tahun_data_realLB); ?>;
const xValuesLB = ["Januari","Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"];
const ctxLB = document.getElementById('grafikHasilLB').getContext("2d");
const chart = new Chart(ctxLB, {
type: 'bar',
data: {
labels: xValuesLB,
datasets: [{
label:'Data Hasil Simulasi ' + tahun_hasilLB,
data: yHasilLB,
borderColor: 'white',
backgroundColor: 'rgba(21, 60, 200, 0.59)',
borderWidth: 1
},
{
label:'Data Real ' + tahun_realLB,
data: yRealLB,
borderColor: 'white',
backgroundColor: 'rgba(72, 226, 146, 0.68)',
borderWidth: 1
}
]
},
options: {
responsive: true ,
scales: {
yAxes: [{
display: true,
ticks: {
beginAtZero: true,
max: max_sumbuyLB,
min: 0
}
}],
xAxes: [{
id: 'x-axis-1'
}]
},
// annotation: {
// drawTime: "afterDraw",
// annotations: [{
// id: 'box1',
// type: 'box',
// xScaleID: 'x-axis-1',
// xMin: '',
// xMax: 'Januari',
// backgroundColor: 'rgba(75, 192, 192, 0.2)',
// borderColor: 'rgba(100, 100, 100, 0.2)',
// content: ['Musim Hujan'],
// font: {
// size: 18
// }
// },
// {
// id: 'box2',
// type: 'box',
// xScaleID: 'x-axis-1',
// xMin: 'Januari',
// xMax: 'Mei',
// backgroundColor: 'rgba(75, 192, 192, 0.2)',
// borderColor: 'rgba(100, 100, 100, 0.2)'
// },
// {
// id: 'box3',
// type: 'box',
// xScaleID: 'x-axis-1',
// xMin: 'Mei',
// xMax: 'November',
// backgroundColor: 'rgba(255, 99, 132, 0.2)',
// borderColor: 'rgba(100, 100, 100, 0.2)'
// },
// {
// id: 'box5',
// type: 'box',
// xScaleID: 'x-axis-1',
// xMin: 'November',
// xMax: 'Desember',
// backgroundColor: 'rgba(75, 192, 192, 0.2)',
// borderColor: 'rgba(100, 100, 100, 0.2)'
// },
// {
// id: 'box6',
// type: 'box',
// xScaleID: 'x-axis-1',
// xMin: 'Desember',
// xMax: '',
// backgroundColor: 'rgba(75, 192, 192, 0.2)',
// borderColor: 'rgba(100, 100, 100, 0.2)'
// }
// ]
// }
}
});
</script>
<?php endif; ?>