| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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());
|