diff --git a/src/components/Dashboard/AttendanceOverview.jsx b/src/components/Dashboard/AttendanceOverview.jsx index 522aa193..b964770e 100644 --- a/src/components/Dashboard/AttendanceOverview.jsx +++ b/src/components/Dashboard/AttendanceOverview.jsx @@ -1,11 +1,13 @@ import React, { useState, useMemo } from "react"; import { useSelector } from "react-redux"; import ReactApexChart from "react-apexcharts"; +import moment from "moment"; import { useAttendanceOverviewData } from "../../hooks/useDashboard_Data"; import flatColors from "../Charts/flatColor"; import ChartSkeleton from "../Charts/Skelton"; import { useSelectedProject } from "../../slices/apiDataManager"; -import { formatDate_DayMonth } from "../../utils/dateUtils"; + +const formatDate_DayMonth = (dateStr) => moment(dateStr).format("DD MMM YY"); const AttendanceOverview = () => { const [dayRange, setDayRange] = useState(7); @@ -22,6 +24,7 @@ const AttendanceOverview = () => { // Use empty array while loading const attendanceData = attendanceOverviewData || []; + // Prepare data for chart and table const { tableData, roles, dates } = useMemo(() => { if (!attendanceData || attendanceData.length === 0) { return { tableData: [], roles: [], dates: [] }; @@ -49,32 +52,58 @@ const AttendanceOverview = () => { return { tableData, roles: uniqueRoles, dates: sortedDates }; }, [attendanceData]); + // Chart data const chartSeries = roles.map((role) => ({ name: role, data: tableData.map((row) => row[role]), })); + // Chart options const chartOptions = { chart: { type: "bar", - stacked: true, + stacked: true, // make false if you want side-by-side bars height: 400, toolbar: { show: false }, }, - plotOptions: { bar: { borderRadius: 2, columnWidth: "60%" } }, - xaxis: { categories: tableData.map((row) => row.date) }, - yaxis: { - show: true, - axisBorder: { show: true, color: "#78909C" }, - axisTicks: { show: true, color: "#78909C", width: 6 }, + plotOptions: { + bar: { + borderRadius: 4, + columnWidth: "55%", + }, + }, + xaxis: { + categories: tableData.map((row) => row.date), + labels: { + rotate: -45, + style: { fontSize: "12px" }, + }, + }, + yaxis: { + axisBorder: { show: true, color: "#78909C" }, + axisTicks: { show: true, color: "#78909C" }, + }, + legend: { + position: "bottom", + horizontalAlign: "center", + fontSize: "12px", + }, + grid: { + borderColor: "#e0e0e0", + strokeDashArray: 3, }, - legend: { position: "bottom" }, fill: { opacity: 1 }, colors: roles.map((_, i) => flatColors[i % flatColors.length]), + tooltip: { + y: { + formatter: (val) => `${val} present`, + }, + }, }; return (
Attendance Overview
@@ -84,6 +113,7 @@ const AttendanceOverview = () => {