import React from "react";
import { cn } from "@/lib/utils";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import {
Area,
AreaChart,
Bar,
BarChart,
CartesianGrid,
Line,
LineChart,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from "recharts";
type ChartType = "bar" | "line" | "area";
interface ChartCardProps {
title: string;
data: Array<{
name: string;
value: number;
color?: string;
}>[];
colors?: string[];
type?: ChartType;
className?: string;
showGrid?: boolean;
}
const ChartCard = ({
title,
data,
colors = ["#F97316", "#E53E3E"],
type = "bar",
className,
showGrid = false,
}: ChartCardProps) => {
const renderChart = () => {
switch (type) {
case "bar":
return (
{showGrid && }
);
case "line":
return (
1 ? undefined : data[0]}>
{showGrid && }
{data.map((dataset, index) => (
))}
);
case "area":
return (
1 ? undefined : data[0]}>
{showGrid && }
{data.map((dataset, index) => (
))}
{data.map((_, index) => (
))}
);
default:
return null;
}
};
return (
{title}
{renderChart()}
);
};
export default ChartCard;