Spaces:
Running
Running
Add 1 files
Browse files- index.html +309 -4
index.html
CHANGED
|
@@ -3,9 +3,10 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Crypto Price Tracker</title>
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
|
|
| 9 |
<style>
|
| 10 |
@keyframes pulse {
|
| 11 |
0% { transform: scale(1); }
|
|
@@ -36,13 +37,30 @@
|
|
| 36 |
0% { transform: rotate(0deg); }
|
| 37 |
100% { transform: rotate(360deg); }
|
| 38 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
</style>
|
| 40 |
</head>
|
| 41 |
<body class="min-h-screen gradient-bg text-white">
|
| 42 |
<div class="container mx-auto px-4 py-12">
|
| 43 |
<header class="text-center mb-12">
|
| 44 |
<h1 class="text-4xl md:text-5xl font-bold mb-4">Crypto Price Tracker</h1>
|
| 45 |
-
<p class="text-xl opacity-90">Real-time cryptocurrency prices
|
| 46 |
<div class="mt-6 flex justify-center">
|
| 47 |
<div class="relative w-full max-w-md">
|
| 48 |
<input
|
|
@@ -92,6 +110,73 @@
|
|
| 92 |
</div>
|
| 93 |
</div>
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
<script>
|
| 96 |
// Configuration
|
| 97 |
const config = {
|
|
@@ -109,6 +194,15 @@
|
|
| 109 |
const searchBtn = document.getElementById('searchBtn');
|
| 110 |
const autoRefreshToggle = document.getElementById('autoRefresh');
|
| 111 |
const lastUpdatedElement = document.getElementById('lastUpdated');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
// State
|
| 114 |
let refreshInterval;
|
|
@@ -129,6 +223,15 @@
|
|
| 129 |
if (e.key === 'Enter') filterCoins();
|
| 130 |
});
|
| 131 |
autoRefreshToggle.addEventListener('change', setupAutoRefresh);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
// Auto Refresh
|
|
@@ -175,7 +278,8 @@
|
|
| 175 |
const priceChangeIcon = priceChange24h >= 0 ? 'fa-arrow-up' : 'fa-arrow-down';
|
| 176 |
|
| 177 |
const card = document.createElement('div');
|
| 178 |
-
card.className = 'bg-white/5 rounded-xl p-6 border border-white/10 transition-all duration-300 card-hover';
|
|
|
|
| 179 |
card.innerHTML = `
|
| 180 |
<div class="flex justify-between items-start mb-4">
|
| 181 |
<div class="flex items-center">
|
|
@@ -224,6 +328,9 @@
|
|
| 224 |
</div>
|
| 225 |
`;
|
| 226 |
|
|
|
|
|
|
|
|
|
|
| 227 |
cryptoContainer.appendChild(card);
|
| 228 |
|
| 229 |
// Render sparkline after the card is added to DOM
|
|
@@ -262,6 +369,204 @@
|
|
| 262 |
ctx.stroke();
|
| 263 |
}
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
// Filter Coins
|
| 266 |
function filterCoins() {
|
| 267 |
const searchTerm = searchInput.value.toLowerCase();
|
|
@@ -317,5 +622,5 @@
|
|
| 317 |
lastUpdatedElement.textContent = now.toLocaleTimeString();
|
| 318 |
}
|
| 319 |
</script>
|
| 320 |
-
|
| 321 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Crypto Price Tracker with Charts</title>
|
| 7 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 10 |
<style>
|
| 11 |
@keyframes pulse {
|
| 12 |
0% { transform: scale(1); }
|
|
|
|
| 37 |
0% { transform: rotate(0deg); }
|
| 38 |
100% { transform: rotate(360deg); }
|
| 39 |
}
|
| 40 |
+
.modal {
|
| 41 |
+
transition: opacity 0.3s ease, transform 0.3s ease;
|
| 42 |
+
}
|
| 43 |
+
.modal-active {
|
| 44 |
+
opacity: 1;
|
| 45 |
+
visibility: visible;
|
| 46 |
+
transform: translate(-50%, -50%) scale(1);
|
| 47 |
+
}
|
| 48 |
+
.modal-inactive {
|
| 49 |
+
opacity: 0;
|
| 50 |
+
visibility: hidden;
|
| 51 |
+
transform: translate(-50%, -50%) scale(0.9);
|
| 52 |
+
}
|
| 53 |
+
.chart-tab.active {
|
| 54 |
+
background-color: rgba(255, 255, 255, 0.2);
|
| 55 |
+
font-weight: 600;
|
| 56 |
+
}
|
| 57 |
</style>
|
| 58 |
</head>
|
| 59 |
<body class="min-h-screen gradient-bg text-white">
|
| 60 |
<div class="container mx-auto px-4 py-12">
|
| 61 |
<header class="text-center mb-12">
|
| 62 |
<h1 class="text-4xl md:text-5xl font-bold mb-4">Crypto Price Tracker</h1>
|
| 63 |
+
<p class="text-xl opacity-90">Real-time cryptocurrency prices with interactive charts</p>
|
| 64 |
<div class="mt-6 flex justify-center">
|
| 65 |
<div class="relative w-full max-w-md">
|
| 66 |
<input
|
|
|
|
| 110 |
</div>
|
| 111 |
</div>
|
| 112 |
|
| 113 |
+
<!-- Modal -->
|
| 114 |
+
<div id="coinModal" class="modal modal-inactive fixed inset-0 z-50">
|
| 115 |
+
<div class="absolute inset-0 bg-black/70 backdrop-blur-sm" id="modalBackdrop"></div>
|
| 116 |
+
<div class="absolute top-1/2 left-1/2 w-11/12 max-w-4xl -translate-x-1/2 -translate-y-1/2">
|
| 117 |
+
<div class="bg-gray-900 rounded-xl border border-white/10 overflow-hidden shadow-2xl">
|
| 118 |
+
<div class="flex justify-between items-center p-4 border-b border-white/10">
|
| 119 |
+
<div class="flex items-center">
|
| 120 |
+
<img id="modalCoinImage" src="" alt="" class="w-8 h-8 mr-3">
|
| 121 |
+
<h3 id="modalCoinName" class="text-xl font-bold"></h3>
|
| 122 |
+
<span id="modalCoinSymbol" class="ml-2 text-sm opacity-80"></span>
|
| 123 |
+
</div>
|
| 124 |
+
<button id="closeModal" class="text-white/50 hover:text-white">
|
| 125 |
+
<i class="fas fa-times text-xl"></i>
|
| 126 |
+
</button>
|
| 127 |
+
</div>
|
| 128 |
+
|
| 129 |
+
<div class="p-6">
|
| 130 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
|
| 131 |
+
<div class="bg-white/5 p-4 rounded-lg border border-white/10">
|
| 132 |
+
<div class="text-sm opacity-80 mb-1">Current Price</div>
|
| 133 |
+
<div id="modalCurrentPrice" class="text-2xl font-bold"></div>
|
| 134 |
+
</div>
|
| 135 |
+
<div class="bg-white/5 p-4 rounded-lg border border-white/10">
|
| 136 |
+
<div class="text-sm opacity-80 mb-1">Market Cap</div>
|
| 137 |
+
<div id="modalMarketCap" class="text-2xl font-bold"></div>
|
| 138 |
+
</div>
|
| 139 |
+
<div class="bg-white/5 p-4 rounded-lg border border-white/10">
|
| 140 |
+
<div class="text-sm opacity-80 mb-1">24h Change</div>
|
| 141 |
+
<div id="modal24hChange" class="text-2xl font-bold"></div>
|
| 142 |
+
</div>
|
| 143 |
+
</div>
|
| 144 |
+
|
| 145 |
+
<div class="mb-4">
|
| 146 |
+
<div class="flex border-b border-white/10">
|
| 147 |
+
<button class="chart-tab px-4 py-2 active" data-period="24h">24 Hours</button>
|
| 148 |
+
<button class="chart-tab px-4 py-2" data-period="7d">7 Days</button>
|
| 149 |
+
<button class="chart-tab px-4 py-2" data-period="30d">30 Days</button>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<div class="h-80 mb-6">
|
| 154 |
+
<canvas id="detailedChart"></canvas>
|
| 155 |
+
</div>
|
| 156 |
+
|
| 157 |
+
<div class="grid grid-cols-2 md:grid-cols-4 gap-3 text-sm">
|
| 158 |
+
<div class="bg-white/5 p-3 rounded border border-white/10">
|
| 159 |
+
<div class="opacity-70">24h High</div>
|
| 160 |
+
<div id="24hHigh" class="text-lg mt-1"></div>
|
| 161 |
+
</div>
|
| 162 |
+
<div class="bg-white/5 p-3 rounded border border-white/10">
|
| 163 |
+
<div class="opacity-70">24h Low</div>
|
| 164 |
+
<div id="24hLow" class="text-lg mt-1"></div>
|
| 165 |
+
</div>
|
| 166 |
+
<div class="bg-white/5 p-3 rounded border border-white/10">
|
| 167 |
+
<div class="opacity-70">24h Volume</div>
|
| 168 |
+
<div id="24hVolume" class="text-lg mt-1"></div>
|
| 169 |
+
</div>
|
| 170 |
+
<div class="bg-white/5 p-3 rounded border border-white/10">
|
| 171 |
+
<div class="opacity-70">Circ. Supply</div>
|
| 172 |
+
<div id="circSupply" class="text-lg mt-1"></div>
|
| 173 |
+
</div>
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
</div>
|
| 178 |
+
</div>
|
| 179 |
+
|
| 180 |
<script>
|
| 181 |
// Configuration
|
| 182 |
const config = {
|
|
|
|
| 194 |
const searchBtn = document.getElementById('searchBtn');
|
| 195 |
const autoRefreshToggle = document.getElementById('autoRefresh');
|
| 196 |
const lastUpdatedElement = document.getElementById('lastUpdated');
|
| 197 |
+
const coinModal = document.getElementById('coinModal');
|
| 198 |
+
const modalBackdrop = document.getElementById('modalBackdrop');
|
| 199 |
+
const closeModal = document.getElementById('closeModal');
|
| 200 |
+
const detailedChart = document.getElementById('detailedChart');
|
| 201 |
+
const chartTabs = document.querySelectorAll('.chart-tab');
|
| 202 |
+
|
| 203 |
+
// Chart instance
|
| 204 |
+
let chartInstance = null;
|
| 205 |
+
let currentCoinId = null;
|
| 206 |
|
| 207 |
// State
|
| 208 |
let refreshInterval;
|
|
|
|
| 223 |
if (e.key === 'Enter') filterCoins();
|
| 224 |
});
|
| 225 |
autoRefreshToggle.addEventListener('change', setupAutoRefresh);
|
| 226 |
+
modalBackdrop.addEventListener('click', closeCoinModal);
|
| 227 |
+
closeModal.addEventListener('click', closeCoinModal);
|
| 228 |
+
|
| 229 |
+
// Add event listeners to chart tabs
|
| 230 |
+
chartTabs.forEach(tab => {
|
| 231 |
+
tab.addEventListener('click', () => {
|
| 232 |
+
changeChartPeriod(tab.dataset.period);
|
| 233 |
+
});
|
| 234 |
+
});
|
| 235 |
}
|
| 236 |
|
| 237 |
// Auto Refresh
|
|
|
|
| 278 |
const priceChangeIcon = priceChange24h >= 0 ? 'fa-arrow-up' : 'fa-arrow-down';
|
| 279 |
|
| 280 |
const card = document.createElement('div');
|
| 281 |
+
card.className = 'bg-white/5 rounded-xl p-6 border border-white/10 transition-all duration-300 card-hover cursor-pointer';
|
| 282 |
+
card.dataset.coinId = coin.id;
|
| 283 |
card.innerHTML = `
|
| 284 |
<div class="flex justify-between items-start mb-4">
|
| 285 |
<div class="flex items-center">
|
|
|
|
| 328 |
</div>
|
| 329 |
`;
|
| 330 |
|
| 331 |
+
// Add click event to show modal with detailed info
|
| 332 |
+
card.addEventListener('click', () => showCoinModal(coin.id));
|
| 333 |
+
|
| 334 |
cryptoContainer.appendChild(card);
|
| 335 |
|
| 336 |
// Render sparkline after the card is added to DOM
|
|
|
|
| 369 |
ctx.stroke();
|
| 370 |
}
|
| 371 |
|
| 372 |
+
// Show Coin Modal
|
| 373 |
+
async function showCoinModal(coinId) {
|
| 374 |
+
try {
|
| 375 |
+
currentCoinId = coinId;
|
| 376 |
+
|
| 377 |
+
// Get the basic coin data from our existing data
|
| 378 |
+
const coinData = allCoinsData.find(c => c.id === coinId);
|
| 379 |
+
if (!coinData) return;
|
| 380 |
+
|
| 381 |
+
// Get more detailed data from API
|
| 382 |
+
const response = await fetch(`https://api.coingecko.com/api/v3/coins/${coinId}/market_chart?vs_currency=${config.vsCurrency}&days=30`);
|
| 383 |
+
if (!response.ok) throw new Error('Could not fetch detailed data');
|
| 384 |
+
|
| 385 |
+
const detailedData = await response.json();
|
| 386 |
+
|
| 387 |
+
// Update modal with basic info
|
| 388 |
+
document.getElementById('modalCoinImage').src = coinData.image;
|
| 389 |
+
document.getElementById('modalCoinName').textContent = coinData.name;
|
| 390 |
+
document.getElementById('modalCoinSymbol').textContent = coinData.symbol.toUpperCase();
|
| 391 |
+
document.getElementById('modalCurrentPrice').textContent = `$${coinData.current_price.toLocaleString()}`;
|
| 392 |
+
document.getElementById('modalMarketCap').textContent = `$${coinData.market_cap.toLocaleString()}`;
|
| 393 |
+
|
| 394 |
+
const priceChange24h = coinData.price_change_percentage_24h;
|
| 395 |
+
const priceChangeClass = priceChange24h >= 0 ? 'price-up' : 'price-down';
|
| 396 |
+
const priceChangeIcon = priceChange24h >= 0 ? 'fa-arrow-up' : 'fa-arrow-down';
|
| 397 |
+
document.getElementById('modal24hChange').innerHTML = `
|
| 398 |
+
<span class="${priceChangeClass}">
|
| 399 |
+
<i class="fas ${priceChangeIcon} mr-1"></i>${Math.abs(priceChange24h).toFixed(2)}%
|
| 400 |
+
</span>
|
| 401 |
+
`;
|
| 402 |
+
|
| 403 |
+
// Update additional info
|
| 404 |
+
document.getElementById('24hHigh').textContent = `$${coinData.high_24h.toLocaleString()}`;
|
| 405 |
+
document.getElementById('24hLow').textContent = `$${coinData.low_24h.toLocaleString()}`;
|
| 406 |
+
document.getElementById('24hVolume').textContent = `$${coinData.total_volume.toLocaleString()}`;
|
| 407 |
+
document.getElementById('circSupply').textContent = `${coinData.circulating_supply.toLocaleString()} ${coinData.symbol.toUpperCase()}`;
|
| 408 |
+
|
| 409 |
+
// Create the initial chart (24h view)
|
| 410 |
+
createDetailedChart(detailedData.prices, '24h');
|
| 411 |
+
|
| 412 |
+
// Show the modal
|
| 413 |
+
coinModal.classList.remove('modal-inactive');
|
| 414 |
+
coinModal.classList.add('modal-active');
|
| 415 |
+
|
| 416 |
+
// Set the first tab as active
|
| 417 |
+
chartTabs.forEach(tab => tab.classList.remove('active'));
|
| 418 |
+
document.querySelector('[data-period="24h"]').classList.add('active');
|
| 419 |
+
|
| 420 |
+
} catch (error) {
|
| 421 |
+
console.error('Error showing coin modal:', error);
|
| 422 |
+
alert('Failed to load detailed coin data. Please try again.');
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
// Close Coin Modal
|
| 427 |
+
function closeCoinModal() {
|
| 428 |
+
coinModal.classList.remove('modal-active');
|
| 429 |
+
coinModal.classList.add('modal-inactive');
|
| 430 |
+
|
| 431 |
+
// Destroy the chart if it exists
|
| 432 |
+
if (chartInstance) {
|
| 433 |
+
chartInstance.destroy();
|
| 434 |
+
chartInstance = null;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
currentCoinId = null;
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
// Create Detailed Chart
|
| 441 |
+
function createDetailedChart(prices, period) {
|
| 442 |
+
// Filter data based on period
|
| 443 |
+
let filteredPrices = [];
|
| 444 |
+
const now = new Date().getTime();
|
| 445 |
+
|
| 446 |
+
if (period === '24h') {
|
| 447 |
+
const twentyFourHoursAgo = now - 24 * 60 * 60 * 1000;
|
| 448 |
+
filteredPrices = prices.filter(price => price[0] >= twentyFourHoursAgo);
|
| 449 |
+
} else if (period === '7d') {
|
| 450 |
+
const sevenDaysAgo = now - 7 * 24 * 60 * 60 * 1000;
|
| 451 |
+
filteredPrices = prices.filter(price => price[0] >= sevenDaysAgo);
|
| 452 |
+
} else { // 30d
|
| 453 |
+
filteredPrices = prices;
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
// Prepare data for chart
|
| 457 |
+
const labels = filteredPrices.map(price => {
|
| 458 |
+
const date = new Date(price[0]);
|
| 459 |
+
if (period === '24h') {
|
| 460 |
+
return date.toLocaleTimeString();
|
| 461 |
+
} else {
|
| 462 |
+
return date.toLocaleDateString();
|
| 463 |
+
}
|
| 464 |
+
});
|
| 465 |
+
|
| 466 |
+
const data = filteredPrices.map(price => price[1]);
|
| 467 |
+
|
| 468 |
+
// Get color based on price trend
|
| 469 |
+
const firstPrice = filteredPrices[0][1];
|
| 470 |
+
const lastPrice = filteredPrices[filteredPrices.length - 1][1];
|
| 471 |
+
const isPositive = lastPrice >= firstPrice;
|
| 472 |
+
const lineColor = isPositive ? '#10b981' : '#ef4444';
|
| 473 |
+
const bgColor = isPositive ? 'rgba(16, 185, 129, 0.1)' : 'rgba(239, 68, 68, 0.1)';
|
| 474 |
+
|
| 475 |
+
// Destroy previous chart if it exists
|
| 476 |
+
if (chartInstance) {
|
| 477 |
+
chartInstance.destroy();
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
// Create new chart
|
| 481 |
+
const ctx = detailedChart.getContext('2d');
|
| 482 |
+
chartInstance = new Chart(ctx, {
|
| 483 |
+
type: 'line',
|
| 484 |
+
data: {
|
| 485 |
+
labels: labels,
|
| 486 |
+
datasets: [{
|
| 487 |
+
label: 'Price',
|
| 488 |
+
data: data,
|
| 489 |
+
borderColor: lineColor,
|
| 490 |
+
backgroundColor: bgColor,
|
| 491 |
+
borderWidth: 2,
|
| 492 |
+
fill: true,
|
| 493 |
+
tension: 0.4,
|
| 494 |
+
pointRadius: 0
|
| 495 |
+
}]
|
| 496 |
+
},
|
| 497 |
+
options: {
|
| 498 |
+
responsive: true,
|
| 499 |
+
maintainAspectRatio: false,
|
| 500 |
+
plugins: {
|
| 501 |
+
legend: {
|
| 502 |
+
display: false
|
| 503 |
+
},
|
| 504 |
+
tooltip: {
|
| 505 |
+
mode: 'index',
|
| 506 |
+
intersect: false,
|
| 507 |
+
callbacks: {
|
| 508 |
+
label: function(context) {
|
| 509 |
+
return `${context.dataset.label}: $${context.parsed.y.toFixed(2)}`;
|
| 510 |
+
}
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
},
|
| 514 |
+
scales: {
|
| 515 |
+
x: {
|
| 516 |
+
grid: {
|
| 517 |
+
color: 'rgba(255, 255, 255, 0.1)',
|
| 518 |
+
display: false
|
| 519 |
+
},
|
| 520 |
+
ticks: {
|
| 521 |
+
color: 'rgba(255, 255, 255, 0.7)',
|
| 522 |
+
maxRotation: 0,
|
| 523 |
+
autoSkip: true,
|
| 524 |
+
maxTicksLimit: 8
|
| 525 |
+
}
|
| 526 |
+
},
|
| 527 |
+
y: {
|
| 528 |
+
grid: {
|
| 529 |
+
color: 'rgba(255, 255, 255, 0.1)'
|
| 530 |
+
},
|
| 531 |
+
ticks: {
|
| 532 |
+
color: 'rgba(255, 255, 255, 0.7)',
|
| 533 |
+
callback: function(value) {
|
| 534 |
+
return '$' + value.toLocaleString();
|
| 535 |
+
}
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
+
});
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
// Change Chart Period
|
| 544 |
+
async function changeChartPeriod(period) {
|
| 545 |
+
if (!currentCoinId) return;
|
| 546 |
+
|
| 547 |
+
try {
|
| 548 |
+
// Set active tab
|
| 549 |
+
chartTabs.forEach(tab => tab.classList.remove('active'));
|
| 550 |
+
document.querySelector(`[data-period="${period}"]`).classList.add('active');
|
| 551 |
+
|
| 552 |
+
// Get the updated data for the selected period
|
| 553 |
+
let days;
|
| 554 |
+
if (period === '24h') days = 1;
|
| 555 |
+
else if (period === '7d') days = 7;
|
| 556 |
+
else days = 30;
|
| 557 |
+
|
| 558 |
+
const response = await fetch(`https://api.coingecko.com/api/v3/coins/${currentCoinId}/market_chart?vs_currency=${config.vsCurrency}&days=${days}`);
|
| 559 |
+
if (!response.ok) throw new Error('Could not fetch chart data');
|
| 560 |
+
|
| 561 |
+
const detailedData = await response.json();
|
| 562 |
+
createDetailedChart(detailedData.prices, period);
|
| 563 |
+
|
| 564 |
+
} catch (error) {
|
| 565 |
+
console.error('Error changing chart period:', error);
|
| 566 |
+
alert('Failed to load chart data. Please try again.');
|
| 567 |
+
}
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
// Filter Coins
|
| 571 |
function filterCoins() {
|
| 572 |
const searchTerm = searchInput.value.toLowerCase();
|
|
|
|
| 622 |
lastUpdatedElement.textContent = now.toLocaleTimeString();
|
| 623 |
}
|
| 624 |
</script>
|
| 625 |
+
</body>
|
| 626 |
</html>
|