ChartJS_Sample/index.html
2025-03-08 21:11:01 +08:00

82 lines
2.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Real-time Dashboard - Average Response Times</title>
<!-- Include Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
}
.chart-container {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Real-time Dashboard - Average Response Times</h1>
<div>
<p>Overall Average Response Time: <span id="overall-average"></span> hours</p>
<canvas id="response-chart" width="400" height="200"></canvas>
</div>
</div>
<script>
// Sample data: Average response times for different priority levels
var priorityLevels = ["Low", "Medium", "High", "Critical"];
var responseTimes = [4.5, 3.2, 5.1, 2.8]; // Initial response times (hours)
// Function to update data and dashboard
function updateDataAndDashboard() {
responseTimes = responseTimes.map(time => time + (Math.random() * 2 - 1)); // Simulate random data update
var overallAverage = responseTimes.reduce((acc, val) => acc + val, 0) / responseTimes.length;
// Update overall average text
document.getElementById('overall-average').textContent = overallAverage.toFixed(2);
// Update chart data
responseChart.data.datasets[0].data = responseTimes;
responseChart.update();
}
// Create initial chart
var ctx = document.getElementById('response-chart').getContext('2d');
var responseChart = new Chart(ctx, {
type: 'line',
data: {
labels: priorityLevels,
datasets: [{
label: 'Average Response Time',
data: responseTimes,
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1,
pointBackgroundColor: 'rgba(54, 162, 235, 1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(54, 162, 235, 1)'
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
// Update data and dashboard every 5 seconds (for demonstration)
setInterval(updateDataAndDashboard, 5000); // 5000 milliseconds = 5 seconds
</script>
</body>
</html>