Pisahkan chart pH di card yang berbeda (bikin baru). Yang disatukan chart Suhu dan kekeruhan
Browse files- index.html +310 -54
index.html
CHANGED
|
@@ -4,10 +4,135 @@
|
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
| 6 |
<title>Bioflok-IoT</title>
|
| 7 |
-
<link rel="stylesheet" href="https:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 10 |
<style>
|
|
|
|
| 11 |
.relative {
|
| 12 |
position: relative;
|
| 13 |
}
|
|
@@ -947,25 +1072,35 @@ margin-left: 5px;
|
|
| 947 |
</div>
|
| 948 |
</div>
|
| 949 |
</div>
|
| 950 |
-
<div class="kolam-charts">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 951 |
<div class="card">
|
| 952 |
<div class="parameter-title">
|
| 953 |
<i class="fas fa-chart-line"></i>
|
| 954 |
-
<span>
|
| 955 |
</div>
|
| 956 |
<div class="chart-container">
|
| 957 |
-
<canvas id="
|
| 958 |
</div>
|
| 959 |
</div>
|
| 960 |
</div>
|
| 961 |
-
|
| 962 |
|
| 963 |
container.appendChild(kolamSection);
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
|
|
|
| 969 |
subscribeToKolamTopics(kolamId);
|
| 970 |
}
|
| 971 |
|
|
@@ -1488,11 +1623,29 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1488 |
let combinedCharts = {};
|
| 1489 |
|
| 1490 |
function initializeCharts() {
|
| 1491 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1492 |
}
|
| 1493 |
|
| 1494 |
function initializeCombinedChart(kolamId) {
|
| 1495 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1496 |
|
| 1497 |
combinedCharts[kolamId] = new Chart(ctx, {
|
| 1498 |
type: 'line',
|
|
@@ -1504,10 +1657,11 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1504 |
data: [],
|
| 1505 |
borderColor: '#FF5252',
|
| 1506 |
backgroundColor: 'rgba(255, 82, 82, 0.1)',
|
| 1507 |
-
tension: 0.
|
| 1508 |
fill: false,
|
| 1509 |
borderWidth: 2,
|
| 1510 |
-
pointRadius:
|
|
|
|
| 1511 |
yAxisID: 'y'
|
| 1512 |
},
|
| 1513 |
{
|
|
@@ -1515,10 +1669,11 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1515 |
data: [],
|
| 1516 |
borderColor: '#4CAF50',
|
| 1517 |
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
| 1518 |
-
tension: 0.
|
| 1519 |
fill: false,
|
| 1520 |
borderWidth: 2,
|
| 1521 |
-
pointRadius:
|
|
|
|
| 1522 |
yAxisID: 'y1'
|
| 1523 |
},
|
| 1524 |
{
|
|
@@ -1526,10 +1681,11 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1526 |
data: [],
|
| 1527 |
borderColor: '#3e92cc',
|
| 1528 |
backgroundColor: 'rgba(62, 146, 204, 0.1)',
|
| 1529 |
-
tension: 0.
|
| 1530 |
fill: false,
|
| 1531 |
borderWidth: 2,
|
| 1532 |
-
pointRadius:
|
|
|
|
| 1533 |
yAxisID: 'y2'
|
| 1534 |
}
|
| 1535 |
]
|
|
@@ -1537,12 +1693,23 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1537 |
options: {
|
| 1538 |
responsive: true,
|
| 1539 |
maintainAspectRatio: false,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1540 |
scales: {
|
| 1541 |
x: {
|
| 1542 |
display: true,
|
| 1543 |
title: {
|
| 1544 |
display: true,
|
| 1545 |
text: 'Waktu'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1546 |
}
|
| 1547 |
},
|
| 1548 |
y: {
|
|
@@ -1553,8 +1720,9 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1553 |
display: true,
|
| 1554 |
text: 'Suhu (°C)'
|
| 1555 |
},
|
| 1556 |
-
|
| 1557 |
-
|
|
|
|
| 1558 |
},
|
| 1559 |
y1: {
|
| 1560 |
type: 'linear',
|
|
@@ -1564,8 +1732,9 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1564 |
display: true,
|
| 1565 |
text: 'pH'
|
| 1566 |
},
|
| 1567 |
-
|
| 1568 |
-
|
|
|
|
| 1569 |
grid: {
|
| 1570 |
drawOnChartArea: false
|
| 1571 |
}
|
|
@@ -1573,61 +1742,148 @@ function updateProgressBar(parameter, value, min = 0, max = 100) {
|
|
| 1573 |
y2: {
|
| 1574 |
type: 'linear',
|
| 1575 |
display: false,
|
| 1576 |
-
|
| 1577 |
-
|
|
|
|
| 1578 |
}
|
| 1579 |
},
|
| 1580 |
plugins: {
|
| 1581 |
legend: {
|
| 1582 |
display: true,
|
| 1583 |
position: 'top'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1584 |
}
|
| 1585 |
}
|
| 1586 |
}
|
| 1587 |
});
|
|
|
|
|
|
|
| 1588 |
}
|
| 1589 |
-
|
| 1590 |
-
|
| 1591 |
-
|
| 1592 |
-
if (!chart) return;
|
| 1593 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1594 |
const now = new Date();
|
| 1595 |
-
const timeLabel = now.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
|
| 1596 |
|
| 1597 |
-
//
|
| 1598 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1599 |
chart.data.labels.push(timeLabel);
|
| 1600 |
|
| 1601 |
-
|
| 1602 |
-
|
| 1603 |
-
|
| 1604 |
-
|
| 1605 |
-
|
| 1606 |
-
|
|
|
|
| 1607 |
|
| 1608 |
-
// Limit
|
| 1609 |
-
|
|
|
|
| 1610 |
chart.data.labels.shift();
|
| 1611 |
-
chart.data.datasets.forEach(
|
| 1612 |
-
dataset.data.shift();
|
| 1613 |
-
});
|
| 1614 |
}
|
|
|
|
|
|
|
| 1615 |
}
|
| 1616 |
|
| 1617 |
-
//
|
| 1618 |
-
|
| 1619 |
-
|
| 1620 |
-
|
| 1621 |
-
|
| 1622 |
-
|
| 1623 |
-
|
| 1624 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1625 |
}
|
| 1626 |
-
|
| 1627 |
-
chart.update({ duration: 0 });
|
| 1628 |
}
|
| 1629 |
-
|
| 1630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1631 |
function updateCurrentTime() {
|
| 1632 |
const now = getWibDate();
|
| 1633 |
const timeString = now.toTimeString().substr(0, 8);
|
|
|
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
| 6 |
<title>Bioflok-IoT</title>
|
| 7 |
+
<link rel="stylesheet" href="https:=== CHART FUNCTIONS ==========
|
| 8 |
+
let combinedCharts = {};
|
| 9 |
+
|
| 10 |
+
function initializeCharts() {
|
| 11 |
+
// Pastikan semua kolam sudah dibuat sebelum inisialisasi chart
|
| 12 |
+
setTimeout(() => {
|
| 13 |
+
for (let i = 1; i <= kolamCount; i++) {
|
| 14 |
+
if (!combinedCharts[i]) {
|
| 15 |
+
initializeCombinedChart(i);
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
}, 100);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function initializeCombinedChart(kolamId) {
|
| 22 |
+
const canvas = document.getElementById(`combined-chart-${kolamId}`);
|
| 23 |
+
if (!canvas) {
|
| 24 |
+
console.warn(`Canvas untuk kolam ${kolamId} tidak ditemukan`);
|
| 25 |
+
return;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const ctx = canvas.getContext('2d');
|
| 29 |
+
|
| 30 |
+
// Hancurkan chart lama jika ada
|
| 31 |
+
if (combinedCharts[kolamId]) {
|
| 32 |
+
combinedCharts[kolamId].destroy();
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
combinedCharts[kolamId] = new Chart(ctx, {
|
| 36 |
+
type: 'line',
|
| 37 |
+
data: {
|
| 38 |
+
labels: [],
|
| 39 |
+
datasets: [
|
| 40 |
+
{
|
| 41 |
+
label: 'Suhu (°C)',
|
| 42 |
+
data: [],
|
| 43 |
+
borderColor: '#FF5252',
|
| 44 |
+
backgroundColor: 'rgba(255, 82, 82, 0.1)',
|
| 45 |
+
tension: 0.4,
|
| 46 |
+
fill: false,
|
| 47 |
+
borderWidth: 2,
|
| 48 |
+
pointRadius: 2,
|
| 49 |
+
pointHoverRadius: 5,
|
| 50 |
+
yAxisID: 'y'
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
label: 'pH',
|
| 54 |
+
data: [],
|
| 55 |
+
borderColor: '#4CAF50',
|
| 56 |
+
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
| 57 |
+
tension: 0.4,
|
| 58 |
+
fill: false,
|
| 59 |
+
borderWidth: 2,
|
| 60 |
+
pointRadius: 2,
|
| 61 |
+
pointHoverRadius: 5,
|
| 62 |
+
yAxisID: 'y1'
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
label: 'Kekeruhan (NTU)',
|
| 66 |
+
data: [],
|
| 67 |
+
borderColor: '#3e92cc',
|
| 68 |
+
backgroundColor: 'rgba(62, 146, 204, 0.1)',
|
| 69 |
+
tension: 0.4,
|
| 70 |
+
fill: false,
|
| 71 |
+
borderWidth: 2,
|
| 72 |
+
pointRadius: 2,
|
| 73 |
+
pointHoverRadius: 5,
|
| 74 |
+
yAxisID: 'y2'
|
| 75 |
+
}
|
| 76 |
+
]
|
| 77 |
+
},
|
| 78 |
+
=======
|
| 79 |
+
// ========== CHART FUNCTIONS ==========
|
| 80 |
+
let tempTurbidityCharts = {};
|
| 81 |
+
let phCharts = {};
|
| 82 |
+
|
| 83 |
+
function initializeCharts() {
|
| 84 |
+
setTimeout(() => {
|
| 85 |
+
for (let i = 1; i <= kolamCount; i++) {
|
| 86 |
+
if (!tempTurbidityCharts[i]) {
|
| 87 |
+
initializeTempTurbidityChart(i);
|
| 88 |
+
}
|
| 89 |
+
if (!phCharts[i]) {
|
| 90 |
+
initializePhChart(i);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
}, 100);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
function initializeTempTurbidityChart(kolamId) {
|
| 97 |
+
const canvas = document.getElementById(`temp-turbidity-chart-${kolamId}`);
|
| 98 |
+
if (!canvas) return;
|
| 99 |
+
|
| 100 |
+
const ctx = canvas.getContext('2d');
|
| 101 |
+
|
| 102 |
+
if (tempTurbidityCharts[kolamId]) {
|
| 103 |
+
tempTurbidityCharts[kolamId].destroy();
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
tempTurbidityCharts[kolamId] = new Chart(ctx, {
|
| 107 |
+
type: 'line',
|
| 108 |
+
data: {
|
| 109 |
+
labels: [],
|
| 110 |
+
datasets: [
|
| 111 |
+
{
|
| 112 |
+
label: 'Suhu (°C)',
|
| 113 |
+
data: [],
|
| 114 |
+
borderColor: '#FF5252',
|
| 115 |
+
backgroundColor: 'rgba(255, 82, 82, 0.1)',
|
| 116 |
+
tension: 0.4,
|
| 117 |
+
borderWidth: 2,
|
| 118 |
+
yAxisID: 'y'
|
| 119 |
+
},
|
| 120 |
+
{
|
| 121 |
+
label: 'Kekeruhan (NTU)',
|
| 122 |
+
data: [],
|
| 123 |
+
borderColor: '#3e92cc',
|
| 124 |
+
backgroundColor: 'rgba(62, 146, 204, 0.1)',
|
| 125 |
+
tension: 0.4,
|
| 126 |
+
borderWidth: 2,
|
| 127 |
+
yAxisID: 'y1'
|
| 128 |
+
}
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 132 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 133 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 134 |
<style>
|
| 135 |
+
/* CSS yang sama seperti sebelumnya */
|
| 136 |
.relative {
|
| 137 |
position: relative;
|
| 138 |
}
|
|
|
|
| 1072 |
</div>
|
| 1073 |
</div>
|
| 1074 |
</div>
|
| 1075 |
+
<div class="kolam-charts grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 1076 |
+
<div class="card">
|
| 1077 |
+
<div class="parameter-title">
|
| 1078 |
+
<i class="fas fa-chart-line"></i>
|
| 1079 |
+
<span>Suhu & Kekeruhan</span>
|
| 1080 |
+
</div>
|
| 1081 |
+
<div class="chart-container">
|
| 1082 |
+
<canvas id="temp-turbidity-chart-${kolamId}"></canvas>
|
| 1083 |
+
</div>
|
| 1084 |
+
</div>
|
| 1085 |
<div class="card">
|
| 1086 |
<div class="parameter-title">
|
| 1087 |
<i class="fas fa-chart-line"></i>
|
| 1088 |
+
<span>pH Air</span>
|
| 1089 |
</div>
|
| 1090 |
<div class="chart-container">
|
| 1091 |
+
<canvas id="ph-chart-${kolamId}"></canvas>
|
| 1092 |
</div>
|
| 1093 |
</div>
|
| 1094 |
</div>
|
| 1095 |
+
`;
|
| 1096 |
|
| 1097 |
container.appendChild(kolamSection);
|
| 1098 |
+
// Initialize charts for this kolam
|
| 1099 |
+
setTimeout(() => {
|
| 1100 |
+
initializeTempTurbidityChart(kolamId);
|
| 1101 |
+
initializePhChart(kolamId);
|
| 1102 |
+
}, 100);
|
| 1103 |
+
// Subscribe to MQTT topics for this kolam
|
| 1104 |
subscribeToKolamTopics(kolamId);
|
| 1105 |
}
|
| 1106 |
|
|
|
|
| 1623 |
let combinedCharts = {};
|
| 1624 |
|
| 1625 |
function initializeCharts() {
|
| 1626 |
+
// Pastikan semua kolam sudah dibuat sebelum inisialisasi chart
|
| 1627 |
+
setTimeout(() => {
|
| 1628 |
+
for (let i = 1; i <= kolamCount; i++) {
|
| 1629 |
+
if (!combinedCharts[i]) {
|
| 1630 |
+
initializeCombinedChart(i);
|
| 1631 |
+
}
|
| 1632 |
+
}
|
| 1633 |
+
}, 100);
|
| 1634 |
}
|
| 1635 |
|
| 1636 |
function initializeCombinedChart(kolamId) {
|
| 1637 |
+
const canvas = document.getElementById(`combined-chart-${kolamId}`);
|
| 1638 |
+
if (!canvas) {
|
| 1639 |
+
console.warn(`Canvas untuk kolam ${kolamId} tidak ditemukan`);
|
| 1640 |
+
return;
|
| 1641 |
+
}
|
| 1642 |
+
|
| 1643 |
+
const ctx = canvas.getContext('2d');
|
| 1644 |
+
|
| 1645 |
+
// Hancurkan chart lama jika ada
|
| 1646 |
+
if (combinedCharts[kolamId]) {
|
| 1647 |
+
combinedCharts[kolamId].destroy();
|
| 1648 |
+
}
|
| 1649 |
|
| 1650 |
combinedCharts[kolamId] = new Chart(ctx, {
|
| 1651 |
type: 'line',
|
|
|
|
| 1657 |
data: [],
|
| 1658 |
borderColor: '#FF5252',
|
| 1659 |
backgroundColor: 'rgba(255, 82, 82, 0.1)',
|
| 1660 |
+
tension: 0.4,
|
| 1661 |
fill: false,
|
| 1662 |
borderWidth: 2,
|
| 1663 |
+
pointRadius: 2,
|
| 1664 |
+
pointHoverRadius: 5,
|
| 1665 |
yAxisID: 'y'
|
| 1666 |
},
|
| 1667 |
{
|
|
|
|
| 1669 |
data: [],
|
| 1670 |
borderColor: '#4CAF50',
|
| 1671 |
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
| 1672 |
+
tension: 0.4,
|
| 1673 |
fill: false,
|
| 1674 |
borderWidth: 2,
|
| 1675 |
+
pointRadius: 2,
|
| 1676 |
+
pointHoverRadius: 5,
|
| 1677 |
yAxisID: 'y1'
|
| 1678 |
},
|
| 1679 |
{
|
|
|
|
| 1681 |
data: [],
|
| 1682 |
borderColor: '#3e92cc',
|
| 1683 |
backgroundColor: 'rgba(62, 146, 204, 0.1)',
|
| 1684 |
+
tension: 0.4,
|
| 1685 |
fill: false,
|
| 1686 |
borderWidth: 2,
|
| 1687 |
+
pointRadius: 2,
|
| 1688 |
+
pointHoverRadius: 5,
|
| 1689 |
yAxisID: 'y2'
|
| 1690 |
}
|
| 1691 |
]
|
|
|
|
| 1693 |
options: {
|
| 1694 |
responsive: true,
|
| 1695 |
maintainAspectRatio: false,
|
| 1696 |
+
animation: {
|
| 1697 |
+
duration: 0 // Nonaktifkan animasi untuk performa realtime
|
| 1698 |
+
},
|
| 1699 |
+
interaction: {
|
| 1700 |
+
intersect: false,
|
| 1701 |
+
mode: 'index'
|
| 1702 |
+
},
|
| 1703 |
scales: {
|
| 1704 |
x: {
|
| 1705 |
display: true,
|
| 1706 |
title: {
|
| 1707 |
display: true,
|
| 1708 |
text: 'Waktu'
|
| 1709 |
+
},
|
| 1710 |
+
ticks: {
|
| 1711 |
+
maxTicksLimit: 8,
|
| 1712 |
+
maxRotation: 0
|
| 1713 |
}
|
| 1714 |
},
|
| 1715 |
y: {
|
|
|
|
| 1720 |
display: true,
|
| 1721 |
text: 'Suhu (°C)'
|
| 1722 |
},
|
| 1723 |
+
// Sumbu Y dinamis - akan menyesuaikan nilai tertinggi
|
| 1724 |
+
beginAtZero: false,
|
| 1725 |
+
grace: '5%' // Tambahkan ruang ekstra di atas nilai tertinggi
|
| 1726 |
},
|
| 1727 |
y1: {
|
| 1728 |
type: 'linear',
|
|
|
|
| 1732 |
display: true,
|
| 1733 |
text: 'pH'
|
| 1734 |
},
|
| 1735 |
+
// Sumbu Y dinamis
|
| 1736 |
+
beginAtZero: false,
|
| 1737 |
+
grace: '5%',
|
| 1738 |
grid: {
|
| 1739 |
drawOnChartArea: false
|
| 1740 |
}
|
|
|
|
| 1742 |
y2: {
|
| 1743 |
type: 'linear',
|
| 1744 |
display: false,
|
| 1745 |
+
// Sumbu Y dinamis
|
| 1746 |
+
beginAtZero: false,
|
| 1747 |
+
grace: '5%'
|
| 1748 |
}
|
| 1749 |
},
|
| 1750 |
plugins: {
|
| 1751 |
legend: {
|
| 1752 |
display: true,
|
| 1753 |
position: 'top'
|
| 1754 |
+
},
|
| 1755 |
+
tooltip: {
|
| 1756 |
+
mode: 'index',
|
| 1757 |
+
intersect: false
|
| 1758 |
}
|
| 1759 |
}
|
| 1760 |
}
|
| 1761 |
});
|
| 1762 |
+
|
| 1763 |
+
console.log(`Chart untuk kolam ${kolamId} berhasil diinisialisasi`);
|
| 1764 |
}
|
| 1765 |
+
function initializePhChart(kolamId) {
|
| 1766 |
+
const canvas = document.getElementById(`ph-chart-${kolamId}`);
|
| 1767 |
+
if (!canvas) return;
|
|
|
|
| 1768 |
|
| 1769 |
+
const ctx = canvas.getContext('2d');
|
| 1770 |
+
|
| 1771 |
+
if (phCharts[kolamId]) {
|
| 1772 |
+
phCharts[kolamId].destroy();
|
| 1773 |
+
}
|
| 1774 |
+
|
| 1775 |
+
phCharts[kolamId] = new Chart(ctx, {
|
| 1776 |
+
type: 'line',
|
| 1777 |
+
data: {
|
| 1778 |
+
labels: [],
|
| 1779 |
+
datasets: [{
|
| 1780 |
+
label: 'pH Air',
|
| 1781 |
+
data: [],
|
| 1782 |
+
borderColor: '#4CAF50',
|
| 1783 |
+
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
| 1784 |
+
tension: 0.4,
|
| 1785 |
+
borderWidth: 2
|
| 1786 |
+
}]
|
| 1787 |
+
},
|
| 1788 |
+
options: {
|
| 1789 |
+
responsive: true,
|
| 1790 |
+
maintainAspectRatio: false,
|
| 1791 |
+
animation: { duration: 0 },
|
| 1792 |
+
scales: {
|
| 1793 |
+
x: {
|
| 1794 |
+
display: true,
|
| 1795 |
+
title: { display: true, text: 'Waktu' }
|
| 1796 |
+
},
|
| 1797 |
+
y: {
|
| 1798 |
+
display: true,
|
| 1799 |
+
title: { display: true, text: 'pH' },
|
| 1800 |
+
beginAtZero: false,
|
| 1801 |
+
grace: '5%'
|
| 1802 |
+
}
|
| 1803 |
+
}
|
| 1804 |
+
}
|
| 1805 |
+
});
|
| 1806 |
+
}
|
| 1807 |
+
|
| 1808 |
+
function updateChartData(kolamId, type, value) {
|
| 1809 |
const now = new Date();
|
| 1810 |
+
const timeLabel = now.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit', second:'2-digit'});
|
| 1811 |
|
| 1812 |
+
// Handle temperature and turbidity chart
|
| 1813 |
+
if (type === 'suhu' || type === 'kekeruhan') {
|
| 1814 |
+
const chart = tempTurbidityCharts[kolamId];
|
| 1815 |
+
if (!chart) {
|
| 1816 |
+
initializeTempTurbidityChart(kolamId);
|
| 1817 |
+
return;
|
| 1818 |
+
}
|
| 1819 |
+
|
| 1820 |
chart.data.labels.push(timeLabel);
|
| 1821 |
|
| 1822 |
+
if (type === 'suhu') {
|
| 1823 |
+
chart.data.datasets[0].data.push(value);
|
| 1824 |
+
chart.data.datasets[1].data.push(null);
|
| 1825 |
+
} else {
|
| 1826 |
+
chart.data.datasets[0].data.push(null);
|
| 1827 |
+
chart.data.datasets[1].data.push(value);
|
| 1828 |
+
}
|
| 1829 |
|
| 1830 |
+
// Limit data points
|
| 1831 |
+
const maxDataPoints = 20;
|
| 1832 |
+
if (chart.data.labels.length > maxDataPoints) {
|
| 1833 |
chart.data.labels.shift();
|
| 1834 |
+
chart.data.datasets.forEach(ds => ds.data.shift());
|
|
|
|
|
|
|
| 1835 |
}
|
| 1836 |
+
|
| 1837 |
+
chart.update('none');
|
| 1838 |
}
|
| 1839 |
|
| 1840 |
+
// Handle pH chart
|
| 1841 |
+
if (type === 'ph') {
|
| 1842 |
+
const chart = phCharts[kolamId];
|
| 1843 |
+
if (!chart) {
|
| 1844 |
+
initializePhChart(kolamId);
|
| 1845 |
+
return;
|
| 1846 |
+
}
|
| 1847 |
+
|
| 1848 |
+
chart.data.labels.push(timeLabel);
|
| 1849 |
+
chart.data.datasets[0].data.push(value);
|
| 1850 |
+
|
| 1851 |
+
const maxDataPoints = 20;
|
| 1852 |
+
if (chart.data.labels.length > maxDataPoints) {
|
| 1853 |
+
chart.data.labels.shift();
|
| 1854 |
+
chart.data.datasets[0].data.shift();
|
| 1855 |
+
}
|
| 1856 |
+
|
| 1857 |
+
chart.update('none');
|
| 1858 |
}
|
|
|
|
|
|
|
| 1859 |
}
|
| 1860 |
+
|
| 1861 |
+
function resetCharts(kolamId) {
|
| 1862 |
+
if (tempTurbidityCharts[kolamId]) {
|
| 1863 |
+
tempTurbidityCharts[kolamId].data.labels = [];
|
| 1864 |
+
tempTurbidityCharts[kolamId].data.datasets.forEach(ds => ds.data = []);
|
| 1865 |
+
tempTurbidityCharts[kolamId].update();
|
| 1866 |
+
}
|
| 1867 |
+
if (phCharts[kolamId]) {
|
| 1868 |
+
phCharts[kolamId].data.labels = [];
|
| 1869 |
+
phCharts[kolamId].data.datasets[0].data = [];
|
| 1870 |
+
phCharts[kolamId].update();
|
| 1871 |
+
}
|
| 1872 |
+
}
|
| 1873 |
+
// Event listener untuk resize window - agar chart menyesuaikan ukuran
|
| 1874 |
+
window.addEventListener('resize', function() {
|
| 1875 |
+
Object.keys(tempTurbidityCharts).forEach(kolamId => {
|
| 1876 |
+
if (tempTurbidityCharts[kolamId]) {
|
| 1877 |
+
tempTurbidityCharts[kolamId].resize();
|
| 1878 |
+
}
|
| 1879 |
+
});
|
| 1880 |
+
Object.keys(phCharts).forEach(kolamId => {
|
| 1881 |
+
if (phCharts[kolamId]) {
|
| 1882 |
+
phCharts[kolamId].resize();
|
| 1883 |
+
}
|
| 1884 |
+
});
|
| 1885 |
+
});
|
| 1886 |
+
// ========== TIME FUNCTIONS ==========
|
| 1887 |
function updateCurrentTime() {
|
| 1888 |
const now = getWibDate();
|
| 1889 |
const timeString = now.toTimeString().substr(0, 8);
|