Files
SMARTDiagnostic/templates/charts.html
T

41 lines
1.3 KiB
HTML

{% extends "base.html" %}
{% block title %}Графики{% endblock %}
{% block content %}
<h1>Общие графики</h1>
<div class="charts-grid">
<div class="card">
<h2>Всего дисков и ошибок</h2>
<canvas id="runsChart" height="120"></canvas>
</div>
<div class="card">
<h2>Макс. температура</h2>
<canvas id="tempMaxChart" height="120"></canvas>
</div>
</div>
<script>
fetch('{{ url_for("api_runs") }}').then(r => r.json()).then(rows => {
rows = rows.slice().reverse();
const labels = rows.map(r => `#${r.id} ${r.hostname}`);
new Chart(document.getElementById('runsChart'), {
type: 'bar',
data: { labels, datasets: [
{ label: 'Всего', data: rows.map(r => r.total), backgroundColor: '#3b82f6', borderRadius: 4 },
{ label: 'Ошибок', data: rows.map(r => r.bad), backgroundColor: '#ef4444', borderRadius: 4 },
]},
options: { scales: { y: { beginAtZero: true } } }
});
new Chart(document.getElementById('tempMaxChart'), {
type: 'line',
data: { labels, datasets: [
{ label: 'Макс. °C', data: rows.map(r => r.max_temp), borderColor: '#f59e0b', backgroundColor: 'rgba(245, 158, 11, 0.2)', tension: 0.3, fill: true },
]},
options: { scales: { y: { beginAtZero: true } } }
});
});
</script>
{% endblock %}