"use client" import { cn } from "@/lib/utils" import React from "react" import { CartesianGrid, Line, LineChart as RechartsLineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts" interface LineChartProps extends React.HTMLAttributes { data: Record[] index: string categories: string[] strokeColors?: string[] tooltipBgColor?: string tooltipBorderColor?: string gridColor?: string valueFormatter?: (value: number) => string showGrid?: boolean showTooltip?: boolean strokeWidth?: number dotSize?: number className?: string } const LineChart = React.forwardRef( ( { data = [], index, categories = [], strokeColors = ["var(--foreground)"], tooltipBgColor = "var(--background)", tooltipBorderColor = "var(--border)", gridColor = "var(--muted)", valueFormatter = (value: number) => value.toString(), showGrid = true, showTooltip = true, strokeWidth = 2, dotSize = 4, className, ...props }, ref ) => { return (
{showGrid && ( )} {showTooltip && ( { if (!active || !payload?.length) return null return (
{index} {label}
{payload.map((entry, index) => (
{entry.dataKey} {valueFormatter(entry.value as number)}
))}
) }} /> )} {categories.map((category, index) => { const strokeColor = strokeColors[index] || strokeColors[0] return ( ) })}
) } ) LineChart.displayName = "LineChart" export { LineChart, type LineChartProps }