feat: enhance TeamLeadsDashboard with ComposedChart and improved tooltip for monthly and cumulative values
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
|
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, BarChart, Bar, ComposedChart } from 'recharts';
|
||||||
|
|
||||||
export default function TeamLeadsDashboard() {
|
export default function TeamLeadsDashboard() {
|
||||||
const [chartData, setChartData] = useState([]);
|
const [chartData, setChartData] = useState([]);
|
||||||
@@ -38,14 +38,18 @@ export default function TeamLeadsDashboard() {
|
|||||||
|
|
||||||
const CustomTooltip = ({ active, payload, label }) => {
|
const CustomTooltip = ({ active, payload, label }) => {
|
||||||
if (active && payload && payload.length) {
|
if (active && payload && payload.length) {
|
||||||
|
// Find the monthly and cumulative values
|
||||||
|
const monthlyData = payload.find(p => p.dataKey === 'value');
|
||||||
|
const cumulativeData = payload.find(p => p.dataKey === 'cumulative');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-white dark:bg-gray-800 p-3 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg">
|
<div className="bg-white dark:bg-gray-800 p-3 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg">
|
||||||
<p className="font-medium text-gray-900 dark:text-white">{`Month: ${label}`}</p>
|
<p className="font-medium text-gray-900 dark:text-white">{`Month: ${label}`}</p>
|
||||||
<p className="text-blue-600 dark:text-blue-400">
|
<p className="text-blue-600 dark:text-blue-400 font-semibold">
|
||||||
{`Monthly Value: ${formatCurrency(payload[0].value)}`}
|
{`Monthly Value: ${monthlyData ? formatCurrency(monthlyData.value) : 'N/A'}`}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-green-600 dark:text-green-400">
|
<p className="text-green-600 dark:text-green-400 text-sm">
|
||||||
{`Cumulative: ${formatCurrency(payload[1].value)}`}
|
{`Cumulative: ${cumulativeData ? formatCurrency(cumulativeData.value) : 'N/A'}`}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -79,10 +83,10 @@ export default function TeamLeadsDashboard() {
|
|||||||
) : (
|
) : (
|
||||||
<div className="h-96">
|
<div className="h-96">
|
||||||
<ResponsiveContainer width="100%" height="100%">
|
<ResponsiveContainer width="100%" height="100%">
|
||||||
<LineChart
|
<ComposedChart
|
||||||
data={chartData}
|
data={chartData}
|
||||||
margin={{
|
margin={{
|
||||||
top: 5,
|
top: 20,
|
||||||
right: 30,
|
right: 30,
|
||||||
left: 20,
|
left: 20,
|
||||||
bottom: 5,
|
bottom: 5,
|
||||||
@@ -101,6 +105,12 @@ export default function TeamLeadsDashboard() {
|
|||||||
/>
|
/>
|
||||||
<Tooltip content={<CustomTooltip />} />
|
<Tooltip content={<CustomTooltip />} />
|
||||||
<Legend />
|
<Legend />
|
||||||
|
<Bar
|
||||||
|
dataKey="value"
|
||||||
|
fill="#3b82f6"
|
||||||
|
name="Monthly Value"
|
||||||
|
radius={[4, 4, 0, 0]}
|
||||||
|
/>
|
||||||
<Line
|
<Line
|
||||||
type="monotone"
|
type="monotone"
|
||||||
dataKey="cumulative"
|
dataKey="cumulative"
|
||||||
@@ -110,17 +120,7 @@ export default function TeamLeadsDashboard() {
|
|||||||
dot={{ fill: '#10b981', strokeWidth: 2, r: 4 }}
|
dot={{ fill: '#10b981', strokeWidth: 2, r: 4 }}
|
||||||
activeDot={{ r: 6, stroke: '#10b981', strokeWidth: 2 }}
|
activeDot={{ r: 6, stroke: '#10b981', strokeWidth: 2 }}
|
||||||
/>
|
/>
|
||||||
<Line
|
</ComposedChart>
|
||||||
type="monotone"
|
|
||||||
dataKey="value"
|
|
||||||
stroke="#3b82f6"
|
|
||||||
strokeWidth={2}
|
|
||||||
name="Monthly Value"
|
|
||||||
dot={{ fill: '#3b82f6', strokeWidth: 2, r: 3 }}
|
|
||||||
activeDot={{ r: 5, stroke: '#3b82f6', strokeWidth: 2 }}
|
|
||||||
strokeDasharray="5 5"
|
|
||||||
/>
|
|
||||||
</LineChart>
|
|
||||||
</ResponsiveContainer>
|
</ResponsiveContainer>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user