dashboard.js 934 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class Dashboard {
  2. constructor() {
  3. this.initLeadsChart();
  4. this.initSalesOrdersValueChart();
  5. }
  6. initLeadsChart() {
  7. const ctx = document.getElementById("leads-chart");
  8. $.post("/api/get-leads-chart-data").then(response => {
  9. this.initBarChart(ctx, response.labels, response.data, "Leads");
  10. });
  11. }
  12. initSalesOrdersValueChart() {
  13. const ctx = document.getElementById("sales-orders-value-chart");
  14. $.post("/api/get-sales-orders-value-chart-data").then(response => {
  15. this.initBarChart(ctx, response.labels, response.data, "Sales Orders Value (GBP)");
  16. });
  17. }
  18. initBarChart(ctx, labels, data, datasetLabel) {
  19. new Chart(ctx, {
  20. type: 'bar',
  21. data: {
  22. labels: labels,
  23. datasets: [{
  24. label: datasetLabel,
  25. data: data,
  26. borderWidth: 1
  27. }]
  28. },
  29. options: {
  30. maintainAspectRatio: false,
  31. scales: {
  32. y: {
  33. beginAtZero: true
  34. }
  35. }
  36. }
  37. });
  38. }
  39. }
  40. $(() => new Dashboard());