"use client"; import { HistoryResponse } from "@/lib/api"; import { LineChart, Line, XAxis, YAxis, Tooltip, Legend, ResponsiveContainer, ReferenceLine, } from "recharts"; interface Props { history: HistoryResponse; } export default function FundingChart({ history }: Props) { // 合并BTC和ETH数据,按时间对齐 const btcMap = new Map( history.BTC.map((p) => [p.timestamp.slice(0, 13), p.fundingRate * 100]) ); const ethMap = new Map( history.ETH.map((p) => [p.timestamp.slice(0, 13), p.fundingRate * 100]) ); const allTimes = Array.from( new Set([...btcMap.keys(), ...ethMap.keys()]) ).sort(); const data = allTimes.map((t) => ({ time: t.slice(5).replace("T", " "), // "02-26 12" BTC: btcMap.get(t) ?? null, ETH: ethMap.get(t) ?? null, })); // 只显示最近 42 条(7天×6次/天) const displayData = data.slice(-42); const CustomTooltip = ({ active, payload, label }: any) => { if (!active || !payload?.length) return null; return (

{label}

{payload.map((p: any) => (

{p.dataKey}: {p.value !== null ? `${p.value.toFixed(4)}%` : "--"}

))}
); }; return ( `${v.toFixed(3)}%`} width={60} /> } /> ); }