import React from 'react'; import { ShoppingCart } from 'lucide-react'; import { AreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, BarChart, Bar, Cell } from 'recharts'; import type { DashboardChartPoint } from './state'; /** 趋势图组件的输入参数。 */ export type DashboardTrendChartProps = { /** 趋势图的日期与营收数据点。 */ chartData: DashboardChartPoint[]; /** 当前选择范围的中文名称。 */ selectedRangeLabel: string; /** 当前范围的营收总额。 */ totalAmount: number; }; /** 读取设计系统颜色变量。 */ const cssColor = (token: string, alpha?: number): string => ( alpha === undefined ? `rgb(var(--color-${token}))` : `rgb(var(--color-${token}) / ${alpha})` ); /** 展示 Dashboard 营收趋势,并根据数据点数量选择柱状图或面积图。 */ export const DashboardTrendChart: React.FC = ({ chartData, selectedRangeLabel, totalAmount }) => (

营收趋势分析

{selectedRangeLabel}的销售额走势

{chartData.length === 0 || totalAmount === 0 ? (

暂无营收数据

所选时间范围内暂无订单记录

) : chartData.length <= 2 ? ( // 数据点少于等于2个时使用美化柱状图。 `¥${value}` } /> [`¥${Number(value).toFixed(2)}`, '营收'] } /> {chartData.map( // index 用于生成稳定的图表扇区键。 (_, index) => , )} ) : ( // 数据点多于2个时使用面积图。 )}
);