Files
admin_hura_8/template/javascript/homepage.html

393 lines
11 KiB
HTML
Raw Normal View History

2024-01-24 11:49:22 +07:00
<script>
2025-11-20 13:10:28 +07:00
const initCustomerAcquisitionChart = () => {
2025-11-27 12:55:33 +07:00
const chartOptions = {
chart: {
2025-12-07 15:58:07 +07:00
height: 350,
2025-11-27 12:55:33 +07:00
sparkline: {
enabled: false,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
toolbar: {
2024-01-24 11:49:22 +07:00
show: false,
},
2025-11-27 12:55:33 +07:00
zoom: {
enabled: false,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
background: "transparent",
},
forecastDataPoints: {
count: 2,
dashArray: [6, 4],
},
grid: {
show: false,
},
yaxis: {
show: false,
min: 125,
max: 181,
},
xaxis: {
categories: Array.from({ length: 15 }, (_, index) => index + 1),
},
tooltip: {
y: {
formatter: (val) => val.toString(),
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
},
stroke: {
curve: "stepline",
width: [2, 1.5],
},
colors: ["#167bff", "rgba(150,150,150,0.3)"],
series: [
{
name: "Khách hàng",
data: [144, 150, 146, 154, 150, 155, 160, 155, 140, 155, 160, 180, 170, 165, 165],
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
{
name: "Quảng cáo",
data: [140, 142, 142, 140, 146, 148, 150, 136, 130, 133, 145, 148, 158, 150, 150],
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
],
}
2024-01-24 11:49:22 +07:00
2025-11-27 12:55:33 +07:00
if (document.getElementById("customer-acquisition-chart")) {
new ApexCharts(document.getElementById("customer-acquisition-chart"), chartOptions).render()
2024-01-24 11:49:22 +07:00
}
2025-11-27 12:55:33 +07:00
}
2024-01-24 11:49:22 +07:00
2025-11-27 12:55:33 +07:00
const initRevenueStatisticsChart = () => {
const chartOptions = {
chart: {
2025-12-07 15:58:07 +07:00
height: 292,
2025-11-27 12:55:33 +07:00
type: "bar",
stacked: true,
background: "transparent",
toolbar: {
show: false,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
},
2025-11-20 13:10:28 +07:00
2025-11-27 12:55:33 +07:00
plotOptions: {
bar: {
borderRadius: 8,
borderRadiusApplication: "end",
borderRadiusWhenStacked: "last",
colors: {
backgroundBarColors: ["rgba(150,150,150,0.07)"],
backgroundBarRadius: 8,
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
columnWidth: "45%",
barHeight: "100%",
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
},
dataLabels: {
enabled: false,
},
colors: ["#ff8b4b", "#6c74f8"],
legend: {
show: true,
horizontalAlign: "center",
offsetX: 0,
offsetY: 6,
},
series: [
{
name: "Đơn hàng",
data: [10, 12, 14, 16, 18, 20, 14, 16, 24, 12],
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
{
name: "Doanh thu",
data: [15, 24, 21, 28, 30, 40, 22, 32, 48, 20],
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
],
xaxis: {
categories: [
new Date("1/1/2016"),
new Date("1/1/2017"),
new Date("1/1/2018"),
new Date("1/1/2019"),
new Date("1/1/2020"),
new Date("1/1/2021"),
new Date("1/1/2022"),
new Date("1/1/2023"),
new Date("1/1/2024"),
new Date("1/1/2025"),
2025-11-20 13:10:28 +07:00
],
2025-11-27 12:55:33 +07:00
axisBorder: {
show: false,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
axisTicks: {
show: false,
},
labels: {
formatter: (val) => {
return new Date(val).getFullYear().toString()
2025-11-20 13:10:28 +07:00
},
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
},
yaxis: {
axisBorder: {
show: false,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
axisTicks: {
2024-01-24 11:49:22 +07:00
show: false,
},
2025-11-27 12:55:33 +07:00
labels: {
show: false,
},
},
tooltip: {
enabled: true,
shared: true,
intersect: false,
},
grid: {
show: false,
},
responsive: [
{
breakpoint: 450,
options: {
plotOptions: {
bar: {
borderRadius: 4,
2025-11-20 13:10:28 +07:00
},
},
2025-11-27 12:55:33 +07:00
xaxis: {
tickAmount: 3,
},
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
},
],
}
2024-01-24 11:49:22 +07:00
2025-11-27 12:55:33 +07:00
if (document.getElementById("revenue-statics-chart")) {
new ApexCharts(document.getElementById("revenue-statics-chart"), chartOptions).render()
2024-01-24 11:49:22 +07:00
}
2025-11-27 12:55:33 +07:00
}
2024-01-24 11:49:22 +07:00
2025-11-27 12:55:33 +07:00
const initGlobalSalesChart = () => {
const data = [
{
name: "Turkey",
orders: 9,
},
{
name: "India",
orders: 12,
},
{
name: "Canada",
orders: 13,
},
{
name: "US",
orders: 16,
},
{
name: "Netherlands",
orders: 14,
},
{
name: "Italy",
orders: 17,
},
{
name: "Other",
orders: 19,
},
]
const chartOptions = {
chart: {
height: 344,
type: "bar",
parentHeightOffset: 0,
background: "transparent",
toolbar: {
show: false,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
},
plotOptions: {
bar: {
horizontal: true,
borderRadius: 4,
distributed: true,
borderRadiusApplication: "end",
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
},
dataLabels: {
enabled: true,
textAnchor: "start",
style: {
colors: ["#fff"],
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
formatter: function (val, opt) {
return opt.w.globals.labels[opt.dataPointIndex] + ": " + val
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
offsetX: -10,
dropShadow: {
enabled: false,
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
},
series: [
2025-11-20 13:10:28 +07:00
{
2025-11-27 12:55:33 +07:00
data: data.map((country) => country.orders),
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
],
legend: {
show: false,
},
stroke: {
width: 0,
colors: ["#fff"],
},
xaxis: {
categories: data.map((country) => country.name),
},
yaxis: {
labels: {
show: false,
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
},
grid: {
show: false,
},
2025-11-20 13:10:28 +07:00
2025-11-27 12:55:33 +07:00
tooltip: {
theme: "dark",
x: {
2025-11-20 13:10:28 +07:00
show: false,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
y: {
formatter: (val) => `${val}%`,
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
},
colors: ["#7179ff", "#4bcd89", "#ff6c88", "#5cb7ff", "#9071ff", "#ff5892", "#ff8b4b"],
}
if (document.getElementById("global-sales-chart")) {
new ApexCharts(document.getElementById("global-sales-chart"), chartOptions).render()
}
}
const initGradientDonutChart = () => {
const seriesData = [35.1, 23.5, 2.4, 5.4]
const chartOptions = {
chart: {
type: "donut",
height: 380,
toolbar: {
show: false,
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
background: "transparent",
},
title: {
text: "Truy cập website",
style: { fontWeight: "500" },
align: "right",
},
stroke: {
show: true,
width: 1,
colors: ["var(--color-base-100)"],
},
fill: {
type: "solid",
},
plotOptions: {
pie: {
startAngle: -45,
endAngle: 315,
donut: {
size: "60%",
labels: {
show: true,
value: {
formatter: (value) => `${value}K`,
color: "var(--color-base-content)",
},
total: {
show: true,
color: "#FF4560",
formatter: () => `${seriesData.reduce((acc, cur) => acc + cur, 0)}K`,
},
},
2024-01-24 11:49:22 +07:00
},
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
},
tooltip: {
enabled: true,
y: {
formatter: (value) => `${value}K`,
2025-11-20 13:10:28 +07:00
},
2025-11-27 12:55:33 +07:00
},
responsive: [
{
breakpoint: 480,
options: {
chart: {
width: 200,
},
legend: {
position: "bottom",
},
2025-11-20 13:10:28 +07:00
},
2024-01-24 11:49:22 +07:00
},
2025-11-27 12:55:33 +07:00
],
labels: [
"Trực tiếp",
"Quảng cáo",
"Liên kết",
"Qua email",
],
colors: ["#0041E8", "#6DC580", "#FFC700", "#E00000"],
series: seriesData,
}
2024-01-24 11:49:22 +07:00
2025-11-27 12:55:33 +07:00
if (document.getElementById("gradient-donut-chart")) {
new ApexCharts(document.getElementById("gradient-donut-chart"), chartOptions).render()
2024-01-24 11:49:22 +07:00
}
2025-11-27 12:55:33 +07:00
}
function initAdminHomeTab() {
document.querySelectorAll("#js-admin-home-tab a").forEach(function (link) {
link.addEventListener("click", function (event) {
event.preventDefault();
// Xóa class current ở tất cả các tab
document.querySelectorAll("#js-admin-home-tab a").forEach(function (el) {
el.classList.remove("btn-active");
});
// Gán class current vào tab đang click
this.classList.add("btn-active");
// Lấy ID từ href để show nội dung
var id = this.getAttribute("href");
// Ẩn tất cả nội dung
document.querySelectorAll(".home-report-holder").forEach(function (holder) {
holder.style.display = "none";
});
// Hiện phần tương ứng
document.querySelector(id).style.display = "block";
});
});
}
2025-11-20 13:10:28 +07:00
2025-11-27 12:55:33 +07:00
document.addEventListener("DOMContentLoaded", () => {
initCustomerAcquisitionChart()
initRevenueStatisticsChart()
initGlobalSalesChart()
initGradientDonutChart()
initAdminHomeTab()
})
2024-01-24 11:49:22 +07:00
</script>