Replace Google Charts with Chart.js horizontal bars and set dark theme default

This commit is contained in:
Harwinder Sekhon
2026-08-16 20:28:54 -04:00
parent 96c926803d
commit c248b39cc5
2 changed files with 51 additions and 46 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="light">
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -11,7 +11,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" crossorigin="anonymous">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap">
<link rel="stylesheet" href="dashboard.css">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<script>
(function () {
var t = localStorage.getItem("xau-theme");
+47 -42
View File
@@ -1,54 +1,59 @@
document.addEventListener('DOMContentLoaded', function() {
// Load Google Charts
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(drawGauges);
// Draw all gauges on the page
function drawGauges() {
// Draw horizontal bar charts for each score using Chart.js
function drawCharts() {
const gaugeContainers = document.querySelectorAll('.gauge-container');
gaugeContainers.forEach(container => {
const label = container.dataset.label;
const score = parseFloat(container.dataset.score);
// Create data table
const data = google.visualization.arrayToDataTable([
['Label', 'Value'],
[label, score]
]);
// Configure gauge options
const options = {
width: 200,
height: 160,
redFrom: -100,
redTo: 0,
greenFrom: 0,
greenTo: 100,
minorTicks: 5,
// Clear any previous content
container.innerHTML = '';
// Create canvas element
const canvas = document.createElement('canvas');
// Set a fixed height for thin bar
canvas.height = 30;
container.appendChild(canvas);
const ctx = canvas.getContext('2d');
// Determine bar colour based on sign
const bgColor = score >= 0 ? 'rgba(40,167,69,0.8)' : 'rgba(220,53,69,0.8)'; // success/red
new Chart(ctx, {
type: 'bar',
data: {
labels: [label],
datasets: [{
label: label,
data: [score],
backgroundColor: bgColor,
borderColor: 'rgba(0,0,0,0.1)',
borderWidth: 1,
barThickness: 12,
maxBarThickness: 12,
}]
},
options: {
indexAxis: 'y',
scales: {
x: {
min: -100,
max: 100,
majorTicks: [-100, -50, 0, 50, 100],
animation: {
duration: 500,
easing: 'out'
display: false,
grid: { display: false },
ticks: { display: false }
},
y: { display: false, grid: { display: false } }
},
plugins: {
legend: { display: false },
tooltip: { enabled: false },
title: { display: false }
},
maintainAspectRatio: false,
responsive: true,
animation: { duration: 500, easing: 'easeOutQuad' }
}
};
// Remove yellow region
delete options.yellowFrom;
delete options.yellowTo;
// Create and draw the gauge
const chart = new google.visualization.Gauge(container);
chart.draw(data, options);
});
});
}
// Re-draw gauges when window is resized
window.addEventListener('resize', function() {
if (typeof google !== 'undefined' && google.visualization) {
drawGauges();
}
});
drawCharts();
window.addEventListener('resize', drawCharts);
});