¨4.0.1¨
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
import Chart from 'chart.js';
|
||||
import Chart from "chart.js/auto";
|
||||
|
||||
$(function () {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: route('admin.sales_analytics.index'),
|
||||
type: "GET",
|
||||
url: route("admin.sales_analytics.index"),
|
||||
success(response) {
|
||||
let data = { labels: response.labels, sales: [], formatted: [], totalOrders: [] };
|
||||
let data = {
|
||||
labels: response.labels,
|
||||
sales: [],
|
||||
formatted: [],
|
||||
totalOrders: [],
|
||||
};
|
||||
|
||||
for (let item of response.data) {
|
||||
data.sales.push(item.total.amount);
|
||||
@@ -19,45 +24,56 @@ $(function () {
|
||||
});
|
||||
|
||||
function initSalesAnalyticsChart(data) {
|
||||
new Chart($('.sales-analytics .chart'), {
|
||||
type: 'bar',
|
||||
new Chart($(".sales-analytics .chart"), {
|
||||
type: "bar",
|
||||
data: {
|
||||
labels: data.labels,
|
||||
datasets: [{
|
||||
data: data.sales,
|
||||
backgroundColor: [
|
||||
'rgba(255, 99, 132, 0.5)',
|
||||
'rgba(54, 162, 235, 0.5)',
|
||||
'rgba(255, 206, 86, 0.5)',
|
||||
'rgba(75, 192, 192, 0.5)',
|
||||
'rgba(153, 102, 255, 0.5)',
|
||||
'rgba(255, 159, 64, 0.5)',
|
||||
],
|
||||
}],
|
||||
datasets: [
|
||||
{
|
||||
data: data.sales,
|
||||
backgroundColor: [
|
||||
"rgba(255, 99, 132, 0.5)",
|
||||
"rgba(54, 162, 235, 0.5)",
|
||||
"rgba(255, 206, 86, 0.5)",
|
||||
"rgba(75, 192, 192, 0.5)",
|
||||
"rgba(153, 102, 255, 0.5)",
|
||||
"rgba(255, 159, 64, 0.5)",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
barThickness: 1,
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
legend: {
|
||||
display: false,
|
||||
},
|
||||
tooltips: {
|
||||
displayColors: false,
|
||||
callbacks: {
|
||||
label(item) {
|
||||
let orders = `${trans('admin::dashboard.sales_analytics.orders')}: ${data.totalOrders[item.index]}`;
|
||||
let sales = `${trans('admin::dashboard.sales_analytics.sales')}: ${data.formatted[item.index]}`;
|
||||
plugins: {
|
||||
legend: false,
|
||||
tooltip: {
|
||||
displayColors: false,
|
||||
callbacks: {
|
||||
label(item) {
|
||||
let orders = `${trans(
|
||||
"admin::dashboard.sales_analytics.orders"
|
||||
)}: ${data.totalOrders[item.dataIndex]}`;
|
||||
|
||||
return [orders, sales];
|
||||
let sales = `${trans(
|
||||
"admin::dashboard.sales_analytics.sales"
|
||||
)}: ${data.formatted[item.dataIndex]}`;
|
||||
|
||||
return [orders, sales];
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
scales: {
|
||||
yAxes: [{
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
beginAtZero: true,
|
||||
// Include the currency symbol in the ticks
|
||||
callback: function (value) {
|
||||
return data.formatted[0].charAt(0) + value;
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user