fix legend in charts
This commit is contained in:
@@ -29,47 +29,37 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
expensesChart.destroy();
|
||||
}
|
||||
|
||||
if (categorySplit) {
|
||||
expensesChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: data.labels,
|
||||
datasets: data.datasets
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
tooltip: {
|
||||
mode: 'index',
|
||||
intersect: false,
|
||||
callbacks: {
|
||||
label: function(context) {
|
||||
const value = context.raw;
|
||||
if (!value) return null;
|
||||
return `${context.dataset.label}: ${value}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
position: 'top',
|
||||
labels: {
|
||||
filter: function(legendItem, chart) {
|
||||
if (!chart.data || !Array.isArray(chart.data.datasets)) return false;
|
||||
const dataset = chart.data.datasets[legendItem.datasetIndex];
|
||||
if (!dataset || !Array.isArray(dataset.data)) return false;
|
||||
return dataset.data.some(val => !!val);
|
||||
}
|
||||
if (categorySplit) {
|
||||
expensesChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: data.labels,
|
||||
datasets: data.datasets
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
tooltip: {
|
||||
mode: 'index',
|
||||
intersect: false,
|
||||
callbacks: {
|
||||
label: function (context) {
|
||||
const value = context.raw;
|
||||
if (!value) return null;
|
||||
return `${context.dataset.label}: ${value}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: { stacked: true },
|
||||
y: { stacked: true, beginAtZero: true }
|
||||
}
|
||||
legend: { position: 'top' }
|
||||
},
|
||||
scales: {
|
||||
x: { stacked: true },
|
||||
y: { stacked: true, beginAtZero: true }
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Tryb zwykły
|
||||
expensesChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
|
Reference in New Issue
Block a user