'use client';
import {Area, AreaChart, CartesianGrid, Line, XAxis, YAxis} from 'recharts';
import {Card, CardContent, CardDescription, CardHeader, CardTitle,} from '@/components/ui/card';
import {
ChartConfig,
ChartContainer,
ChartLegend,
ChartLegendContent,
ChartTooltip,
ChartTooltipContent,
} from '@/components/ui/chart';
import type {TrafficTrendPoint} from '@/lib/services/openflare';
import {formatCompactNumber, formatTrendHour} from './dashboard-utils';
const chartConfig = {
requests: {
label: '请求量',
color: 'hsl(var(--chart-1))',
},
errors: {
label: '错误量',
color: 'hsl(var(--chart-5))',
},
} satisfies ChartConfig;
export function TrafficTrendChart({ points }: { points: TrafficTrendPoint[] }) {
const data = points.map((point) => ({
hour: formatTrendHour(point.bucket_started_at),
requests: point.request_count,
errors: point.error_count,
}));
if (data.length === 0) {
return (
24 小时请求趋势
观察整体请求量和错误量是否出现异常抬升。
暂无趋势数据
);
}
return (
24 小时请求趋势
观察整体请求量和错误量是否出现异常抬升。
formatCompactNumber(Number(value))}
/>
(
{formatCompactNumber(Number(value))}
{name === 'requests' ? '请求' : '错误'}
)}
/>
}
/>
} />
);
}