class Dashboard { constructor() { this.initLeadsChart(); this.initSalesOrdersValueChart(); } initLeadsChart() { const ctx = document.getElementById("leads-chart"); $.post("/api/get-leads-chart-data").then(response => { this.initBarChart(ctx, response.labels, response.data, "Leads"); }); } initSalesOrdersValueChart() { const ctx = document.getElementById("sales-orders-value-chart"); $.post("/api/get-sales-orders-value-chart-data").then(response => { this.initBarChart(ctx, response.labels, response.data, "Sales Orders Value (GBP)"); }); } initBarChart(ctx, labels, data, datasetLabel) { new Chart(ctx, { type: 'bar', data: { labels: labels, datasets: [{ label: datasetLabel, data: data, borderWidth: 1 }] }, options: { maintainAspectRatio: false, scales: { y: { beginAtZero: true } } } }); } } $(() => new Dashboard());