I have faced a problem please help me. here I want to show a bar chart in odoo website and fetch data in bar chart from controller here is my code.
class OpAttendanceController(http.Controller):
@http.route('/dashboard', website=True, auth='public')
def TotalItems(self, **kw):
total_paid = 0.0
total_due = 0.0
payslips = request.env['student.payslip'].search([])
for payslip in payslips:
total_paid += payslip.paid_amount
total_due += payslip.due_amount
return http.request.render('daffodil_smartedu_dashboard.dashboard', {
'total_paid': total_paid,
'total_due': total_due,
}
and here is my javascript
var ctx = document.getElementById('myChart').getContext('2d');
var total_paid = parseFloat(total_paid)
var total_due = parseFloat(total_due)
fetch('/dashboard')
.then(response => response.text())
.then(data => {
var total_paid = data.total_paid;
var total_due = data.total_due;
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Total Paid', 'Total Due'],
datasets: [{
label: 'Amount',
data: [total_paid, total_due],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
});
the bar chart is not showing I think javascript can not get the data of total_paid and total_due and total_due