diff --git a/src/app/dashboard/_PageSections/charts/Bar.tsx b/src/app/dashboard/_PageSections/charts/Bar.tsx index a18c00b..24f9cef 100644 --- a/src/app/dashboard/_PageSections/charts/Bar.tsx +++ b/src/app/dashboard/_PageSections/charts/Bar.tsx @@ -1,7 +1,6 @@ 'use client'; - -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/Card'; -import React from 'react'; +import React, { useState } from 'react'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { BarChart, Bar, @@ -10,132 +9,178 @@ import { CartesianGrid, Tooltip, Legend, - ResponsiveContainer + ResponsiveContainer, + LabelList } from 'recharts'; const data = [ - { - date: '2000-01', - uv: 4000, - pv: 2400, - amt: 2400 - }, - { - date: '2000-02', - uv: 3000, - pv: 1398, - amt: 2210 - }, - { - date: '2000-03', - uv: 2000, - pv: 9800, - amt: 2290 - }, - { - date: '2000-04', - uv: 2780, - pv: 3908, - amt: 2000 - }, - { - date: '2000-05', - uv: 1890, - pv: 4800, - amt: 2181 - }, - { - date: '2000-06', - uv: 2390, - pv: 3800, - amt: 2500 - }, - { - date: '2000-07', - uv: 3490, - pv: 4300, - amt: 2100 - }, - { - date: '2000-08', - uv: 4000, - pv: 2400, - amt: 2400 - }, - { - date: '2000-09', - uv: 3000, - pv: 1398, - amt: 2210 - }, - { - date: '2000-10', - uv: 2000, - pv: 9800, - amt: 2290 - }, - { - date: '2000-11', - uv: 2780, - pv: 3908, - amt: 2000 - }, - { - date: '2000-12', - uv: 1890, - pv: 4800, - amt: 2181 - } + { date: '2000-01', uv: 4000, pv: 2400, amt: 2400 }, + { date: '2000-02', uv: 3000, pv: 1398, amt: 2210 }, + { date: '2000-03', uv: 2000, pv: 9800, amt: 2290 }, + { date: '2000-04', uv: 2780, pv: 3908, amt: 2000 }, + { date: '2000-05', uv: 1890, pv: 4800, amt: 2181 }, + { date: '2000-06', uv: 2390, pv: 3800, amt: 2500 }, + { date: '2000-07', uv: 3490, pv: 4300, amt: 2100 }, + { date: '2000-08', uv: 4000, pv: 2400, amt: 2400 }, + { date: '2000-09', uv: 3000, pv: 1398, amt: 2210 }, + { date: '2000-10', uv: 2000, pv: 9800, amt: 2290 }, + { date: '2000-11', uv: 2780, pv: 3908, amt: 2000 }, + { date: '2000-12', uv: 1890, pv: 4800, amt: 2181 } ]; -const monthTickFormatter = (tick) => { - let date = new Date(tick); - let dateTick = date.getMonth() + 1; +// Enhanced data with quarter information +const enhancedData = data.map(item => { + const date = new Date(item.date); + const month = date.getMonth(); + const quarter = Math.floor(month / 3) + 1; + return { + ...item, + quarter: `Q${quarter}`, + formattedMonth: new Date(item.date).toLocaleString('default', { month: 'short' }) + }; +}); + +// Custom tooltip component +const CustomTooltip = ({ active, payload, label }) => { + if (active && payload && payload.length) { + const date = new Date(label); + const monthName = date.toLocaleString('default', { month: 'long' }); + const year = date.getFullYear(); + + return ( +
+

{`${monthName} ${year}`}

+ {payload.map((entry, index) => ( +
+
+

{`${entry.name}: ${entry.value.toLocaleString()}`}

+
+ ))} +
+ ); + } + return null; +}; - return dateTick.toString(); +// Custom legend component +const CustomLegend = ({ payload }) => { + return ( +
+ {payload.map((entry, index) => ( +
+
+ {entry.value === 'pv' ? 'Page Views' : 'Unique Visitors'} +
+ ))} +
+ ); +}; + +const monthTickFormatter = (tick) => { + const date = new Date(tick); + return date.toLocaleString('default', { month: 'short' }); }; const renderQuarterTick = (tickProps) => { const { x, y, payload } = tickProps; - const { value, offset } = payload; + const { value } = payload; const date = new Date(value); const month = date.getMonth(); const quarterNo = Math.floor(month / 3) + 1; - const isMidMonth = month % 3 === 1; - + if (month % 3 === 1) { - return {`Q${quarterNo}`}; - } - - const isLast = month === 11; - - if (month % 3 === 0 || isLast) { - const pathX = Math.floor(isLast ? x + offset : x - offset) + 0.5; - - return ; + return ( + + {`Q${quarterNo}`} + + ); } return null; }; -const BarChartComp = () => { +const CustomizedAxisTick = (props) => { + const { x, y, payload } = props; + const date = new Date(payload.value); + const month = date.getMonth() + 1; + + return ( + + + {month} + + + ); +}; + +const ModernBarChart = () => { + const [activeIndex, setActiveIndex] = useState(null); + + const handleMouseEnter = (_, index) => { + setActiveIndex(index); + }; + + const handleMouseLeave = () => { + setActiveIndex(null); + }; + return ( - - Quarterly Revenue: - + + + + Quarterly Revenue Performance + + + - - + + + + + + + + + + + + + + + { scale="band" xAxisId="quarter" /> - - - - - + + } cursor={{ fill: 'rgba(0, 0, 0, 0.05)' }} /> + } /> + + + +
+ Monthly revenue data for year 2000 +
); }; -export default BarChartComp; +export default ModernBarChart;