snapspend-wizard / components /spending-chart.js
eddygonzalez's picture
IT SHOULD BE AN ANDROID AND IOS APP AND I WANT TO USE THE PHONE CAMERA TO TAKE PICTURE OF THE RECEIT AND IT TRANSORMS INTO INFORMATION TO BE STORED
7b78975 verified
Raw History Blame Contribute Delete
3.48 kB
class CustomSpendingChart extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.chart-container {
position: relative;
height: 300px;
}
</style>
<div>
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-bold text-gray-800">Spending Overview</h2>
<select class="px-3 py-1 border rounded-lg text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
<option>Last 6 Months</option>
<option>This Year</option>
<option>Last Year</option>
</select>
</div>
<div class="chart-container">
<canvas id="spendingChart"></canvas>
</div>
</div>
`;
// Initialize chart after the element is rendered
setTimeout(() => {
this.initChart();
}, 0);
}
initChart() {
const canvas = this.shadowRoot.getElementById('spendingChart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
// Chart data (would normally come from props or API)
const data = {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [
{
label: 'Food',
data: [120, 190, 150, 200, 180, 220],
backgroundColor: '#6366F1',
borderRadius: 4
},
{
label: 'Transport',
data: [80, 90, 70, 85, 75, 95],
backgroundColor: '#10B981',
borderRadius: 4
},
{
label: 'Shopping',
data: [200, 150, 180, 220, 250, 200],
backgroundColor: '#8B5CF6',
borderRadius: 4
},
{
label: 'Entertainment',
data: [50, 60, 70, 65, 80, 75],
backgroundColor: '#F59E0B',
borderRadius: 4
}
]
};
new Chart(ctx, {
type: 'bar',
data: data,
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'bottom',
},
tooltip: {
mode: 'index',
intersect: false,
}
},
scales: {
x: {
stacked: true,
grid: {
display: false
}
},
y: {
stacked: true,
beginAtZero: true,
ticks: {
callback: function(value) {
return '$' + value;
}
}
}
}
}
});
}
}
customElements.define('custom-spending-chart', CustomSpendingChart);