'use client'; import { useMemo } from 'react'; import dynamic from 'next/dynamic'; import { TrendingUp } from 'lucide-react'; import type { EChartsOption } from 'echarts'; const ReactECharts = dynamic(() => import('echarts-for-react'), { ssr: false }); export interface TrendPoint { date: string; count: number; } export default function TrendChart({ data, peak, avg, total, }: { data: TrendPoint[]; peak: TrendPoint; avg: number; total: number; }) { const option = useMemo( () => ({ grid: { top: 30, right: 24, bottom: 30, left: 50 }, tooltip: { trigger: 'axis', backgroundColor: '#101812', borderColor: '#27342c', textStyle: { color: '#edf1e8' }, formatter: (params: unknown) => { const arr = params as Array<{ name: string; value: number }>; const p = arr[0]; return `
${p.name}
消息数:${p.value} 条
`; }, }, xAxis: { type: 'category', data: data.map((d) => d.date.slice(5)), axisLine: { lineStyle: { color: '#27342c' } }, axisTick: { show: false }, axisLabel: { color: '#737f75', fontSize: 11 }, }, yAxis: { type: 'value', splitLine: { lineStyle: { color: 'rgba(154,174,158,0.12)' } }, axisLabel: { color: '#737f75', fontSize: 11 }, }, series: [ { type: 'line', smooth: true, symbol: 'circle', symbolSize: 6, data: data.map((d) => d.count), lineStyle: { color: '#7dd3a8', width: 2 }, itemStyle: { color: '#7dd3a8' }, areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: 'rgba(125,211,168,0.34)' }, { offset: 1, color: 'rgba(125,211,168,0.02)' }, ], }, }, }, ], }), [data], ); return (
消息走势
过去 {data.length} 天 · {total.toLocaleString()} 条
峰值 {peak.count} 条/天 {peak.date && · {peak.date}} 均值 {avg.toFixed(1)} 总计 {total.toLocaleString()} 条
{data.length > 0 ? ( ) : (
暂无数据 · 点击右上「重扫」加载
)}
); }