Do not attempt to render budget graph when no data available

This commit is contained in:
Yingtong Li 2023-05-01 18:28:42 +10:00
parent 5994cd38b6
commit 7f6bf1b07f
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -156,52 +156,56 @@ function makeGrid() {
function makeCharts() { function makeCharts() {
// Display expense, revenue charts on budget view page // Display expense, revenue charts on budget view page
new Chart(document.getElementById('chartExpenses'), { if (document.getElementById('chartExpenses')) {
type: 'pie', new Chart(document.getElementById('chartExpenses'), {
data: { type: 'pie',
labels: expense_data.map(e => e['Description']), data: {
datasets: [{ labels: expense_data.map(e => e['Description']),
label: 'Expenses', datasets: [{
data: expense_data.map(e => e['Unit price'] * e['Units']) label: 'Expenses',
}] data: expense_data.map(e => e['Unit price'] * e['Units'])
}, }]
options: { },
plugins: { options: {
tooltip: { plugins: {
callbacks: { tooltip: {
label: i => '$' + i.parsed.toFixed(2) callbacks: {
label: i => '$' + i.parsed.toFixed(2)
}
} }
} }
}
},
});
new Chart(document.getElementById('chartRevExp'), {
type: 'bar',
data: {
labels: ['Revenue', 'Expenses'],
datasets: [{
label: 'Budget',
data: [revTotal - revTotalIWT, (expTotal * (1 + emergency_fund_mult))],
backgroundColor: ['#36a2eb', '#ff6384']
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}, },
plugins: { });
legend: { }
display: false
if (document.getElementById('chartRevExp')) {
new Chart(document.getElementById('chartRevExp'), {
type: 'bar',
data: {
labels: ['Revenue', 'Expenses'],
datasets: [{
label: 'Budget',
data: [revTotal - revTotalIWT, (expTotal * (1 + emergency_fund_mult))],
backgroundColor: ['#36a2eb', '#ff6384']
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}, },
tooltip: { plugins: {
callbacks: { legend: {
label: i => '$' + i.parsed.y.toFixed(2) display: false
},
tooltip: {
callbacks: {
label: i => '$' + i.parsed.y.toFixed(2)
}
} }
} }
} },
}, });
}); }
} }