'use client' import { useMemo } from 'react' import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Area, AreaChart, ReferenceLine, Scatter, ComposedChart } from 'recharts' import { TrendingUp } from 'lucide-react' interface Transaction { id: number amount: number prediction: string final_score: number } interface TransactionChartProps { transactions: Transaction[] } export default function TransactionChart({ transactions }: TransactionChartProps) { const chartData = useMemo(() => { if (transactions.length === 0) return [] // Create rolling average for smoother visualization const windowSize = Math.max(3, Math.floor(transactions.length / 50)) return transactions.map((t, i) => { const start = Math.max(0, i - windowSize + 1) const window = transactions.slice(start, i + 1) const avgAmount = window.reduce((sum, tx) => sum + tx.amount, 0) / window.length return { index: i, amount: t.amount, smoothAmount: avgAmount, score: t.final_score, isFraud: t.prediction === 'Fraud', id: t.id } }) }, [transactions]) const CustomTooltip = ({ active, payload, label }: any) => { if (active && payload && payload.length) { const data = payload[0].payload return (
Transaction #{data.id}
${data.amount.toFixed(2)}
Risk Score: 0.5 ? 'text-red-400' : 'text-green-400'}> {(data.score * 100).toFixed(1)}%
{data.isFraud && (⚠️ Fraud Detected
)}Start processing transactions to see the flow chart