document.addEventListener("DOMContentLoaded", function() { const ctx = document.getElementById('cegg-price-history-chart-0'); const { dates, prices, merchants, currency, locale } = priceHistoryData; const rootStyles = getComputedStyle(document.documentElement); const borderColor = rootStyles.getPropertyValue('--cegg-primary').trim(); const rgb = rootStyles.getPropertyValue('--cegg-primary-rgb').trim(); const backgroundColor = `rgba(${rgb}, 0.2)`; const computedStyles = getComputedStyle(ctx); const bodyColorRgb = computedStyles.getPropertyValue('--cegg-body-color-rgb').trim(); const color = `rgb(${bodyColorRgb})`; const gridColor = `rgba(${bodyColorRgb}, 0.1)`; const data = { labels: dates, datasets: [{ data: prices, stepped: 'before', borderColor: borderColor, backgroundColor: backgroundColor, fill: true, borderWidth: 1, radius: 1, tension: 0.1 }] }; const config = { type: 'line', data: data, options: { interaction: { intersect: false, mode: 'index' }, scales: { x: { type: 'category', ticks: { color: color, autoSkip: true, maxTicksLimit: 8 }, grid: { color: gridColor, } }, y: { title: { display: false, }, beginAtZero: false, ticks: { color: color, autoSkip: true, maxTicksLimit: 6, callback: function(value, index, values) { return new Intl.NumberFormat(locale, { style: 'currency', currency: currency }).format(value); } }, grid: { color: gridColor, }, } }, plugins: { legend: { display: false, labels: { color: color, } }, tooltip: { callbacks: { label: function(tooltipItem) { const price = tooltipItem.raw; const merchant = merchants[tooltipItem.dataIndex]; const formattedPrice = new Intl.NumberFormat(locale, { style: 'currency', currency: currency }).format(price); return `${merchant}: ${formattedPrice}`; } } }, } } }; const priceHistoryChart = new Chart(ctx, config); });
Reviews
There are no reviews yet.