ukryawanie 0 na wykresie

This commit is contained in:
Mateusz Gruszczyński
2025-08-01 12:23:08 +02:00
parent 76194e2f57
commit beed40868d

View File

@@ -32,6 +32,19 @@ document.addEventListener("DOMContentLoaded", function () {
expensesChart.destroy();
}
const tooltipOptions = {
mode: 'index',
intersect: false,
callbacks: {
label: function (context) {
if (context.parsed.y === 0) {
return ''; // pomija kategorie o wartości 0
}
return context.dataset.label + ': ' + context.parsed.y;
}
}
};
if (categorySplit) {
expensesChart = new Chart(ctx, {
type: 'bar',
@@ -39,10 +52,7 @@ document.addEventListener("DOMContentLoaded", function () {
options: {
responsive: true,
plugins: {
tooltip: {
mode: 'index',
intersect: false
},
tooltip: tooltipOptions,
legend: { position: 'top' }
},
scales: {
@@ -64,6 +74,9 @@ document.addEventListener("DOMContentLoaded", function () {
},
options: {
responsive: true,
plugins: {
tooltip: tooltipOptions
},
scales: { y: { beginAtZero: true } }
}
});
@@ -133,7 +146,15 @@ document.addEventListener("DOMContentLoaded", function () {
document.querySelectorAll('.range-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
const range = this.getAttribute('data-range');
loadExpenses(range);
if (range === "currentmonth") {
const today = new Date();
const firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
const formatDate = (d) => d.toISOString().split('T')[0];
loadExpenses('custom', formatDate(firstDay), formatDate(today));
} else {
loadExpenses(range);
}
});
});